Code example for DialogFragment

Methods: getDialog, getActivity

0
		return builder.create();
	} 
	 
	private void startConnection(String username) {
		if(username.length() > 0) {
			SharedPreferences prefs = getActivity().getSharedPreferences("settings", Context.MODE_PRIVATE);
			Editor edit = prefs.edit();
			edit.putString(PREF_PLAYERNAME, username);
			edit.commit();
			 
			Netplay.getAppInstance(getActivity().getApplicationContext()).connectToDefaultServer(username);
			getDialog().dismiss();
			((MainActivity)getActivity()).onNetConnectingStarted();
		} 
	} 
} 
Connect your IDE to all the code out there  Get Codota for Java