List of usage examples for android.widget EditText EditText
public EditText(Context context)
From source file:com.example.moneymeterexample.AddExpenseActivity.java
protected Dialog onCreateDialog(int id) { switch (id) { case DATE_DIALOG_ID: return new DatePickerDialog(this, pDateSetListener, mYear, mMonth, mDay); case NEW_CATEGORY_ID: AlertDialog.Builder new_cat_dialog = new AlertDialog.Builder(this); new_cat_dialog.setMessage("Enter the name of new category"); new_cat_dialog.setTitle("New Category"); final EditText new_cat_txt = new EditText(this); new_cat_dialog.setView(new_cat_txt); new_cat_dialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override/*from ww w. ja v a 2s . co m*/ public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub String cat = new_cat_txt.getText().toString(); String last = cat_list.remove((cat_list.size()) - 1); cat_list.add(cat); cat_list.add(last); ((BaseAdapter) category.getAdapter()).notifyDataSetChanged(); } }); new_cat_dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub dialog.cancel(); } }); return new_cat_dialog.create(); case DELETE_CONFIRM_ID: AlertDialog.Builder delete_dialog = new AlertDialog.Builder(this); delete_dialog.setMessage("Are you sure you want to delete this entry?"); delete_dialog.setTitle("Delete Confirmation"); delete_dialog.setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub deleteRecord(); amt.setText(""); date.setText(""); cat_list.remove(category.getSelectedItem().toString()); ((BaseAdapter) category.getAdapter()).notifyDataSetChanged(); notes.setText(""); } }); delete_dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub dialog.cancel(); } }); return delete_dialog.create(); } return null; }
From source file:com.dhaval.mobile.plugin.ChildBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject //from w w w. j a v a 2 s .co m */ public String showWebPage(final String url, JSONObject options) { // Determine if we should hide the location bar. if (options != null) { showLocationBar = options.optBoolean("showLocationBar", true); showAddressBar = options.optBoolean("showAddressBar", true); } // Create dialog in new thread Runnable runnable = new Runnable() { /** * Convert our DIP units to Pixels * * @return int */ private int dpToPixels(int dipValue) { int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue, ctx.getContext().getResources().getDisplayMetrics()); return value; } public void run() { // Let's create the main dialog dialog = new Dialog(ctx.getContext(), android.R.style.Theme_NoTitleBar); dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog; dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { public void onDismiss(DialogInterface dialog) { try { JSONObject obj = new JSONObject(); obj.put("type", CLOSE_EVENT); sendUpdate(obj, false); } catch (JSONException e) { Log.d(LOG_TAG, "Should never happen"); } } }); // Main container layout LinearLayout main = new LinearLayout(ctx.getContext()); main.setOrientation(LinearLayout.VERTICAL); // Toolbar layout RelativeLayout toolbar = new RelativeLayout(ctx.getContext()); toolbar.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, this.dpToPixels(44))); toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2)); toolbar.setHorizontalGravity(Gravity.LEFT); toolbar.setVerticalGravity(Gravity.TOP); // Action Button Container layout RelativeLayout actionButtonContainer = new RelativeLayout(ctx.getContext()); actionButtonContainer.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); actionButtonContainer.setHorizontalGravity(Gravity.LEFT); actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL); actionButtonContainer.setId(1); // Back button ImageButton back = new ImageButton(ctx.getContext()); RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); back.setLayoutParams(backLayoutParams); back.setContentDescription("Back Button"); back.setId(2); try { back.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_left.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); // Forward button ImageButton forward = new ImageButton(ctx.getContext()); RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2); forward.setLayoutParams(forwardLayoutParams); forward.setContentDescription("Forward Button"); forward.setId(3); try { forward.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_right.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } forward.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goForward(); } }); // Edit Text Box edittext = new EditText(ctx.getContext()); RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1); textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5); edittext.setLayoutParams(textLayoutParams); edittext.setId(4); edittext.setSingleLine(true); edittext.setText(url); edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI); edittext.setImeOptions(EditorInfo.IME_ACTION_GO); edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE edittext.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { navigate(edittext.getText().toString()); return true; } return false; } }); if (!showAddressBar) { edittext.setVisibility(EditText.INVISIBLE); } // Close button ImageButton close = new ImageButton(ctx.getContext()); RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); close.setLayoutParams(closeLayoutParams); forward.setContentDescription("Close Button"); close.setId(5); try { close.setImageBitmap(loadDrawable("www/childbrowser/icon_close.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); // WebView webview = new WebView(ctx.getContext()); webview.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); webview.setWebChromeClient(new WebChromeClient()); WebViewClient client = new ChildBrowserClient(edittext); webview.setWebViewClient(client); WebSettings settings = webview.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(true); settings.setPluginsEnabled(true); settings.setDomStorageEnabled(true); webview.loadUrl(url); webview.setId(6); webview.getSettings().setLoadWithOverviewMode(true); webview.getSettings().setUseWideViewPort(true); webview.requestFocus(); webview.requestFocusFromTouch(); // Add the back and forward buttons to our action button container layout actionButtonContainer.addView(back); actionButtonContainer.addView(forward); // Add the views to our toolbar toolbar.addView(actionButtonContainer); toolbar.addView(edittext); toolbar.addView(close); // Don't add the toolbar if its been disabled if (getShowLocationBar()) { // Add our toolbar to our main view/layout main.addView(toolbar); } // Add our webview to our main view/layout main.addView(webview); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.FILL_PARENT; lp.height = WindowManager.LayoutParams.FILL_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); } private Bitmap loadDrawable(String filename) throws java.io.IOException { InputStream input = ctx.getAssets().open(filename); return BitmapFactory.decodeStream(input); } }; this.ctx.runOnUiThread(runnable); return ""; }
From source file:net.gaast.giggity.ChooserActivity.java
private void showAddDialog() { AlertDialog.Builder d = new AlertDialog.Builder(this); d.setTitle(R.string.add_dialog);// ww w .j a v a 2 s. c o m final EditText urlBox = new EditText(this); urlBox.setHint(R.string.enter_url); urlBox.setSingleLine(); urlBox.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI); d.setView(urlBox); d.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { openSchedule(urlBox.getText().toString(), false, null); } }); /* Apparently the "Go"/"Done" button still just simulates an ENTER keypress. Neat!... http://stackoverflow.com/questions/5677563/listener-for-done-button-on-edittext */ urlBox.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) { openSchedule(urlBox.getText().toString(), false, null); return true; } else { return false; } } }); d.setNeutralButton(R.string.qr_scan, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); try { Intent intent = new Intent(BARCODE_SCANNER); intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); startActivityForResult(intent, 0); } catch (ActivityNotFoundException e) { new AlertDialog.Builder(ChooserActivity.this) .setMessage("Please install the Barcode Scanner app").setTitle("Error").show(); } } }); d.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); d.show(); }
From source file:it.mb.whatshare.Dialogs.java
/** * Shows a dialog to get a name for the inbound device being paired and * starts a new {@link CallGooGlInbound} action if the chosen name is valid. * // ww w . ja va 2 s. c o m * @param deviceType * the model of the device being paired as suggested by the * device itself * @param sharedSecret * the keys used when encrypting the message between devices * @param activity * the caller activity */ public static void promptForInboundName(final String deviceType, final int[] sharedSecret, final MainActivity activity) { Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { @Override public void run() { DialogFragment prompt = new PatchedDialogFragment() { public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = getBuilder(activity); final EditText input = new EditText(getContext()); input.setInputType(InputType.TYPE_CLASS_TEXT); input.setText(deviceType); input.setSelection(deviceType.length()); // @formatter:off builder.setTitle(R.string.device_name_chooser_title).setView(input) .setPositiveButton(android.R.string.ok, null); // @formatter:on final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener( new DeviceNameChooserPrompt(alertDialog, input, activity, new Callback<String>() { @Override public void run() { // @formatter:off new CallGooGlInbound(activity, getParam(), deviceType) .execute(sharedSecret); ((InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(input.getWindowToken(), 0); // @formatter:on } })); return alertDialog; } }; prompt.show(activity.getSupportFragmentManager(), "chooseName"); } }); }
From source file:com.jwork.dhammapada.ChapterFragment.java
@Override public void onClick(View view) { log.v(this, "onClick(" + view.getId() + ")"); // if (view == btnSearch) { // btnSearch.setVisibility(View.INVISIBLE); // txtSearch.setVisibility(View.VISIBLE); // txtSearch.requestFocus(); // InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); // imm.showSoftInput(txtSearch, InputMethodManager.SHOW_IMPLICIT); // }/*from w w w. ja v a 2s . com*/ final AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); alert.setTitle(getString(R.string.search)); // Set an EditText view to get user input final EditText input = new EditText(getActivity()); alert.setView(input); alert.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { search(input.getText().toString()); } }); alert.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); } }); alert.show(); }
From source file:bruce.kk.brucetodos.MainActivity.java
/** * ???/*from w ww . j a v a 2s .c o m*/ * * @param position */ private void modifyItem(final int position) { final UnFinishItem item = dataList.get(position); LogDetails.d(item); LinearLayout linearLayout = new LinearLayout(MainActivity.this); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); linearLayout.setLayoutParams(layoutParams); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setBackgroundColor(getResources().getColor(android.R.color.black)); final EditText editText = new EditText(MainActivity.this); editText.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); editText.setTextColor(getResources().getColor(android.R.color.holo_green_light)); editText.setHint(item.content); editText.setHintTextColor(getResources().getColor(android.R.color.holo_orange_dark)); linearLayout.addView(editText); Button btnModify = new Button(MainActivity.this); btnModify.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); btnModify.setText(""); btnModify.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); btnModify.setTextColor(getResources().getColor(android.R.color.holo_blue_bright)); btnModify.setBackgroundColor(getResources().getColor(android.R.color.black)); linearLayout.addView(btnModify); Button btnDeleteItem = new Button(MainActivity.this); btnDeleteItem.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); btnDeleteItem.setText(""); btnDeleteItem.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); btnDeleteItem.setTextColor(getResources().getColor(android.R.color.holo_blue_bright)); btnDeleteItem.setBackgroundColor(getResources().getColor(android.R.color.black)); linearLayout.addView(btnDeleteItem); final PopupWindow popupWindow = new PopupWindow(linearLayout, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); popupWindow.setBackgroundDrawable(new BitmapDrawable()); // ? popupWindow.setTouchable(true); popupWindow.setFocusable(true); popupWindow.setOutsideTouchable(true); popupWindow.showAtLocation(contentMain, Gravity.CENTER, 0, 0); btnModify.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { LogDetails.d(": " + editText.getText().toString()); if (!TextUtils.isEmpty(editText.getText().toString().trim())) { Date date = new Date(); item.content = editText.getText().toString().trim(); item.modifyDay = date; item.finishDay = null; ProgressDialogUtils.showProgressDialog(); presenter.modifyItem(item); dataList.set(position, item); refreshData(true); popupWindow.dismiss(); } else { Toast.makeText(MainActivity.this, "~", Toast.LENGTH_SHORT).show(); } } }); btnDeleteItem.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dataList.remove(position); presenter.deleteItem(item); refreshData(false); popupWindow.dismiss(); } }); }
From source file:com.cricketkorner.cricket.VitamioListActivity.java
private void ListFunction() { listView = (ListView) findViewById(R.id.listView); //copying array for (int i = 0; i < Singleton.getInstance().getChannelList().size(); i++) { title.add(Singleton.getInstance().getChannelList().get(i).getChannelName()); desc.add("Long Press This Channel To Report, Id: " + Singleton.getInstance().getChannelList().get(i).getChannelId()); thumb.add(R.drawable.ic_launcher); }/*ww w . j a v a 2 s . c om*/ listView.setAdapter(new VersionAdapter(VitamioListActivity.this)); listView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) { AlertDialog.Builder alert = new AlertDialog.Builder(VitamioListActivity.this); alert.setTitle("Report Broken Link"); alert.setMessage("Message: (Channel not working?)"); // Set an EditText view to get user input final EditText input = new EditText(VitamioListActivity.this); alert.setView(input); alert.setPositiveButton("Submit", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { String value = input.getText().toString(); if (isNetworkAvailable()) { new ReportFeedback().execute("http://yoururl.com/LiveStreaming/reportFeedback.php", value, Singleton.getInstance().getChannelList().get(position).getChannelId()); } } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { // Canceled. } }); alert.show(); return false; } }); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { int pos = arg2; LayoutInflater layoutInflator = getLayoutInflater(); View layout = layoutInflator.inflate(R.layout.custom_toast, (ViewGroup) findViewById(R.id.toast_layout_root)); ImageView iv = (ImageView) layout.findViewById(R.id.toast_iv); TextView tv = (TextView) layout.findViewById(R.id.toast_tv); iv.setBackgroundResource(thumb.get(pos)); tv.setText(title.get(pos)); Intent intent = new Intent(VitamioListActivity.this, VideoViewDemo.class); intent.putExtra("path", Singleton.getInstance().getChannelList().get(pos).getChannelPath()); startAppAd.onBackPressed(); startActivity(intent); } }); }
From source file:com.manning.androidhacks.hack017.CreateAccountAdapter.java
private EditText createEditText(String hint, int inputType, int imeOption, boolean shouldMoveToNext, final String key) { EditText ret = new EditText(mContext); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);/*from w w w. j a va 2 s . co m*/ ret.setLayoutParams(params); ret.setHint(hint); ret.setInputType(inputType); ret.setImeOptions(imeOption); if (shouldMoveToNext) { ret.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (mDelegate != null) { if (EditorInfo.IME_ACTION_NEXT == actionId) { mDelegate.scroll(CreateAccountDelegate.FORWARD); } else { processForm(); } return true; } else { return false; } } }); } ret.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { mFormData.put(key, s.toString()); } }); return ret; }
From source file:com.dmsl.anyplace.SelectBuildingActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.main_menu_add_building: { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("Add Building"); alert.setMessage("Private Building's ID"); // Set an EditText view to get user input final EditText editText = new EditText(this); alert.setView(editText);//from ww w . j av a2 s .co m alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { try { // http://anyplace.cs.ucy.ac.cy/viewer/?buid=building_2f25420e-3cb1-4bc1-9996-3939e5530d30_1414014035379 // OR // building_2f25420e-3cb1-4bc1-9996-3939e5530d30_1414014035379 String input = editText.getText().toString().trim(); String buid = input; if (input.startsWith("http")) { Uri uri = Uri.parse(URLDecoder.decode(input, "UTF-8")); buid = uri.getQueryParameter("buid"); if (buid == null) { throw new Exception("Missing buid parameter"); } } new FetchBuildingsByBuidTask( new FetchBuildingsByBuidTask.FetchBuildingsByBuidTaskListener() { @Override public void onSuccess(String result, BuildingModel b) { ArrayList<BuildingModel> list = new ArrayList<BuildingModel>(1); list.add(b); setBuildingSpinner(list); } @Override public void onErrorOrCancel(String result) { Toast.makeText(getBaseContext(), result, Toast.LENGTH_SHORT).show(); } }, SelectBuildingActivity.this, buid).execute(); } catch (Exception e) { Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_SHORT).show(); } } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Canceled. } }); alert.show(); return true; } } return false; }