Code example for EditText

Methods: setInputType, setView

	 * @param activity The activity that opens (and owns) this dialog 
	public static void startUrlEntry(final TorrentsActivity activity) {
		new DialogFragment() {
			public onCreateDialog(android.os.Bundle savedInstanceState) {
				final EditText urlInput = new EditText(activity);
				((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(
						InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
				return new AlertDialog.Builder(activity).setView(urlInput)
						.setPositiveButton(android.R.string.ok, new OnClickListener() {
							public void onClick(DialogInterface dialog, int which) {
								// Assume text entry box input as URL and treat the filename (after the last /) as title 
								String url = urlInput.getText().toString();
								if (activity != null && !TextUtils.isEmpty(url))
									activity.addTorrentByUrl(url, url.substring(url.lastIndexOf("/")));
						}).setNegativeButton(android.R.string.cancel, null).create();
Experience pair programming with AI  Get Codota for Java