Example usage for android.widget EditText EditText

List of usage examples for android.widget EditText EditText

Introduction

In this page you can find the example usage for android.widget EditText EditText.

Prototype

public EditText(Context context) 

Source Link

Usage

From source file:com.todoroo.astrid.actfm.ActFmLoginActivity.java

private EditText addEditField(LinearLayout body, int hint) {
    TextView label = new TextView(ActFmLoginActivity.this);
    label.setText(hint);//from   w  w w  .j  ava2  s  . c  om
    body.addView(label);
    EditText field = new EditText(ActFmLoginActivity.this);
    field.setHint(hint);
    body.addView(field);
    return field;
}

From source file:com.cmput301w15t15.travelclaimsapp.activitys.EditClaimActivity.java

/**
 * Function that is called when you press the add tag
 * /*from  w  w  w.  j av a2s .com*/
 * Creates a alert dialog that gives the user the option 
 * of adding a previously added tag or entering a new tag name
 * 
 * @param view
 */
public void addTagButton(View view) {
    final EditText enterTag = new EditText(this);
    final Spinner tagSpinner = new Spinner(this);
    //Linear layout that holds enterTag and tagSpinner views
    LinearLayout ll = new LinearLayout(this);
    ll.setOrientation(LinearLayout.VERTICAL);
    tagSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View arg1, int position, long id) {
            enterTag.setText(parent.getItemAtPosition(position).toString());
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub      
        }
    });

    enterTag.setHint("Enter tag");
    AlertDialog.Builder alert = new AlertDialog.Builder(this);

    //get all the tags currently added to claims in application claimlist
    ArrayList<Tag> tags = ClaimListController.getTagList();
    String t[] = new String[tags.size()];
    for (int i = 0; i < tags.size(); i++) {
        t[i] = tags.get(i).getName();
    }
    //create a arrayadaptor for displaying the tagSpinner view, and set it
    ArrayAdapter<String> tagA = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, t);
    tagSpinner.setAdapter(tagA);
    //add views to linear layout and set the Linear layout view as the alert dialog view 
    ll.addView(tagSpinner);
    ll.addView(enterTag);
    alert.setView(ll);

    alert.setPositiveButton("Add", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            Tag tag = new Tag(enterTag.getText().toString());
            if (theClaim.getTagList().getTag(enterTag.getText().toString()) != null) {
                return;
            }
            ClaimListController.addTag(theClaim, tag);
            tagAdaptor.notifyDataSetChanged();
        }
    });
    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.cancel();
        }
    });

    alert.show();
}

From source file:com.remobile.dialogs.Notification.java

/**
 * Builds and shows a native Android prompt dialog with given title, message, buttons.
 * This dialog only shows up to 3 buttons.  Any labels after that will be ignored.
 * The following results are returned to the JavaScript callback identified by callbackId:
 * buttonIndex         Index number of the button selected
 * input1            The text entered in the prompt dialog box
 *
 * @param message         The message the dialog should display
 * @param title           The title of the dialog
 * @param buttonLabels    A comma separated list of button labels (Up to 3 buttons)
 * @param callbackContext The callback context.
 *//*from   w  w w.j a v a 2 s . co  m*/
public synchronized void prompt(final String message, final String title, final JSONArray buttonLabels,
        final String defaultText, final CallbackContext callbackContext) {
    final Activity activity = this.cordova.getActivity();
    Runnable runnable = new Runnable() {
        public void run() {
            final EditText promptInput = new EditText(activity);
            promptInput.setHint(defaultText);
            AlertDialog.Builder dlg = createDialog(); // new AlertDialog.Builder(this.cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
            dlg.setMessage(message);
            dlg.setTitle(title);
            dlg.setCancelable(false);

            dlg.setView(promptInput);

            final JSONObject result = new JSONObject();

            // First button
            if (buttonLabels.length() > 0) {
                try {
                    dlg.setNegativeButton(buttonLabels.getString(0), new AlertDialog.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                            try {
                                result.put("buttonIndex", 1);
                                result.put("input1",
                                        promptInput.getText().toString().trim().length() == 0 ? defaultText
                                                : promptInput.getText());
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
                        }
                    });
                } catch (JSONException e) {
                }
            }

            // Second button
            if (buttonLabels.length() > 1) {
                try {
                    dlg.setNeutralButton(buttonLabels.getString(1), new AlertDialog.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                            try {
                                result.put("buttonIndex", 2);
                                result.put("input1",
                                        promptInput.getText().toString().trim().length() == 0 ? defaultText
                                                : promptInput.getText());
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
                        }
                    });
                } catch (JSONException e) {
                }
            }

            // Third button
            if (buttonLabels.length() > 2) {
                try {
                    dlg.setPositiveButton(buttonLabels.getString(2), new AlertDialog.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                            try {
                                result.put("buttonIndex", 3);
                                result.put("input1",
                                        promptInput.getText().toString().trim().length() == 0 ? defaultText
                                                : promptInput.getText());
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
                        }
                    });
                } catch (JSONException e) {
                }
            }
            dlg.setOnCancelListener(new AlertDialog.OnCancelListener() {
                public void onCancel(DialogInterface dialog) {
                    dialog.dismiss();
                    try {
                        result.put("buttonIndex", 0);
                        result.put("input1", promptInput.getText().toString().trim().length() == 0 ? defaultText
                                : promptInput.getText());
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
                }
            });

            changeTextDirection(dlg);
        }

        ;
    };
    this.cordova.getActivity().runOnUiThread(runnable);
}

From source file:com.gimranov.zandy.app.AttachmentActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    final String attachmentKey = b.getString("attachmentKey");
    final String itemKey = b.getString("itemKey");
    final String content = b.getString("content");
    final String mode = b.getString("mode");
    AlertDialog dialog;/* w w  w. j  a  v  a2  s. c  o  m*/
    switch (id) {
    case DIALOG_CONFIRM_NAVIGATE:
        dialog = new AlertDialog.Builder(this).setTitle(getResources().getString(R.string.view_online_warning))
                .setPositiveButton(getResources().getString(R.string.view),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                // The behavior for invalid URIs might be nasty, but
                                // we'll cross that bridge if we come to it.
                                try {
                                    Uri uri = Uri.parse(content);
                                    startActivity(new Intent(Intent.ACTION_VIEW).setData(uri));
                                } catch (ActivityNotFoundException e) {
                                    // There can be exceptions here; not sure what would prompt us to have
                                    // URIs that the browser can't load, but it apparently happens.
                                    Toast.makeText(getApplicationContext(), getResources()
                                            .getString(R.string.attachment_intent_failed_for_uri, content),
                                            Toast.LENGTH_SHORT).show();
                                }
                            }
                        })
                .setNeutralButton(getResources().getString(R.string.cancel),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                // do nothing
                            }
                        })
                .create();
        return dialog;
    case DIALOG_CONFIRM_DELETE:
        dialog = new AlertDialog.Builder(this)
                .setTitle(getResources().getString(R.string.attachment_delete_confirm))
                .setPositiveButton(getResources().getString(R.string.menu_delete),
                        new DialogInterface.OnClickListener() {
                            @SuppressWarnings("unchecked")
                            public void onClick(DialogInterface dialog, int whichButton) {
                                Attachment a = Attachment.load(attachmentKey, db);
                                a.delete(db);
                                ArrayAdapter<Attachment> la = (ArrayAdapter<Attachment>) getListAdapter();
                                la.clear();
                                for (Attachment at : Attachment.forItem(Item.load(itemKey, db), db)) {
                                    la.add(at);
                                }
                            }
                        })
                .setNegativeButton(getResources().getString(R.string.cancel),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                // do nothing
                            }
                        })
                .create();
        return dialog;
    case DIALOG_NOTE:
        final EditText input = new EditText(this);
        input.setText(content, BufferType.EDITABLE);

        AlertDialog.Builder builder = new AlertDialog.Builder(this)
                .setTitle(getResources().getString(R.string.note)).setView(input).setPositiveButton(
                        getResources().getString(R.string.ok), new DialogInterface.OnClickListener() {
                            @SuppressWarnings("unchecked")
                            public void onClick(DialogInterface dialog, int whichButton) {
                                Editable value = input.getText();
                                String fixed = value.toString().replaceAll("\n\n", "\n<br>");
                                if (mode != null && mode.equals("new")) {
                                    Log.d(TAG, "Attachment created with parent key: " + itemKey);
                                    Attachment att = new Attachment(getBaseContext(), "note", itemKey);
                                    att.setNoteText(fixed);
                                    att.dirty = APIRequest.API_NEW;
                                    att.save(db);
                                } else {
                                    Attachment att = Attachment.load(attachmentKey, db);
                                    att.setNoteText(fixed);
                                    att.dirty = APIRequest.API_DIRTY;
                                    att.save(db);
                                }
                                ArrayAdapter<Attachment> la = (ArrayAdapter<Attachment>) getListAdapter();
                                la.clear();
                                for (Attachment a : Attachment.forItem(Item.load(itemKey, db), db)) {
                                    la.add(a);
                                }
                                la.notifyDataSetChanged();
                            }
                        })
                .setNeutralButton(getResources().getString(R.string.cancel),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                // do nothing
                            }
                        });
        // We only want the delete option when this isn't a new note
        if (mode == null || !"new".equals(mode)) {
            builder = builder.setNegativeButton(getResources().getString(R.string.menu_delete),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            Bundle b = new Bundle();
                            b.putString("attachmentKey", attachmentKey);
                            b.putString("itemKey", itemKey);
                            removeDialog(DIALOG_CONFIRM_DELETE);
                            AttachmentActivity.this.b = b;
                            showDialog(DIALOG_CONFIRM_DELETE);
                        }
                    });
        }
        dialog = builder.create();
        return dialog;
    case DIALOG_FILE_PROGRESS:
        mProgressDialog = new ProgressDialog(this);
        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        mProgressDialog
                .setMessage(getResources().getString(R.string.attachment_downloading, b.getString("title")));
        mProgressDialog.setIndeterminate(true);
        return mProgressDialog;
    default:
        Log.e(TAG, "Invalid dialog requested");
        return null;
    }
}

From source file:com.citrus.sample.WalletPaymentFragment.java

private void showPrompt(final Utils.PaymentType paymentType) {
    final AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
    String message = null;/*from  ww w .j av  a2s.c o m*/
    String positiveButtonText = null;

    switch (paymentType) {
    case LOAD_MONEY:
    case AUTO_LOAD_MONEY:
        message = "Please enter the amount to load.";
        positiveButtonText = "Load Money";
        break;
    case CITRUS_CASH:
    case NEW_CITRUS_CASH:
        message = "Please enter the transaction amount.";
        positiveButtonText = "Pay";
        break;
    case PG_PAYMENT:
    case NEW_PG_PAYMENT:
    case WALLET_PG_PAYMENT:
        message = "Please enter the transaction amount.";
        positiveButtonText = "Make Payment";
        break;
    }

    LinearLayout linearLayout = new LinearLayout(getActivity());
    linearLayout.setOrientation(LinearLayout.VERTICAL);

    alert.setTitle("Transaction Amount?");
    alert.setMessage(message);
    // Set an EditText view to get user input
    final EditText input = new EditText(getActivity());
    input.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
    alert.setView(input);
    alert.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int whichButton) {
            String value = input.getText().toString();

            mListener.onPaymentTypeSelected(paymentType, new Amount(value));

            input.clearFocus();
            // Hide the keyboard.
            InputMethodManager imm = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(input.getWindowToken(), 0);
        }
    });

    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.cancel();
        }
    });

    input.requestFocus();
    alert.show();
}

From source file:com.mummyding.app.leisure.ui.MainActivity.java

private void showSearchDialog() {
    final EditText editText = new EditText(this);
    editText.setGravity(Gravity.CENTER);
    editText.setSingleLine();/*from w  w w. ja  v  a2  s.  c o m*/
    new AlertDialog.Builder(this).setTitle(getString(R.string.text_search_books)).setIcon(R.mipmap.ic_search)
            .setView(editText)
            .setPositiveButton(getString(R.string.text_ok), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (Utils.hasString(editText.getText().toString())) {
                        Intent intent = new Intent(MainActivity.this, SearchBooksActivity.class);
                        Bundle bundle = new Bundle();
                        bundle.putString(getString(R.string.id_search_text), editText.getText().toString());
                        intent.putExtras(bundle);
                        startActivity(intent);
                    }
                }
            }).show();
}

From source file:com.rsltc.profiledata.main.MainActivity.java

private void showSaveDialog(final List<JSONObject> jsonObjectList) {
    AlertDialog.Builder builder = new AlertDialog.Builder(thisActivity);
    builder.setTitle("Dataset title");

    final EditText input = new EditText(thisActivity);
    input.setInputType(InputType.TYPE_CLASS_TEXT);
    builder.setView(input);/*from w w w.ja  va 2 s  .com*/

    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            final String m_Text = input.getText().toString();
            Runnable r = new Runnable() {
                @Override
                public void run() {
                    exportFile(jsonObjectList, m_Text);
                }
            };

            Thread t = new Thread(r);
            t.start();
        }
    });
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });

    builder.show();
}

From source file:com.todoroo.astrid.activity.FilterListFragment.java

public static void showCreateShortcutDialog(final Activity activity, final Intent shortcutIntent,
        final Filter filter) {
    FrameLayout frameLayout = new FrameLayout(activity);
    frameLayout.setPadding(10, 0, 10, 0);
    final EditText editText = new EditText(activity);
    if (filter.listingTitle == null)
        filter.listingTitle = ""; //$NON-NLS-1$
    editText.setText(filter.listingTitle.replaceAll("\\(\\d+\\)$", "").trim()); //$NON-NLS-1$ //$NON-NLS-2$
    frameLayout.addView(editText, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT,
            FrameLayout.LayoutParams.WRAP_CONTENT));

    final Runnable createShortcut = new Runnable() {
        @Override//w  w  w .j a va2 s  . c  o m
        public void run() {
            String label = editText.getText().toString();
            createShortcut(activity, filter, shortcutIntent, label);
        }
    };
    editText.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_NULL) {
                createShortcut.run();
                return true;
            }
            return false;
        }
    });

    new AlertDialog.Builder(activity).setTitle(R.string.FLA_shortcut_dialog_title)
            .setMessage(R.string.FLA_shortcut_dialog).setView(frameLayout)
            .setIcon(android.R.drawable.ic_dialog_info)
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    createShortcut.run();
                }
            }).setNegativeButton(android.R.string.cancel, null).show().setOwnerActivity(activity);
}

From source file:com.support.android.designlibdemo.PetsDetailActivity.java

/**********************************************************************************************/

private AlertDialog createPublicationDialog(String titulo, String message) {
    // Instanciamos un nuevo AlertDialog Builder y le asociamos titulo y mensaje
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setTitle(titulo);
    alertDialogBuilder.setMessage(message);
    RelativeLayout linearLayout = new RelativeLayout(this);
    final EditText link = new EditText(this);
    link.setText(buildDescription());/*from w w w .  ja  v  a2 s. c o  m*/
    link.setTextSize(12);
    link.setWidth(750);
    linearLayout.addView(link);
    linearLayout.setPadding(70, 0, 0, 0);
    alertDialogBuilder.setView(linearLayout);
    link.invalidate();
    linearLayout.invalidate();
    //        final String petId = getIntent().getStringExtra("id");

    // Creamos un nuevo OnClickListener para el boton OK que realice la conexion
    DialogInterface.OnClickListener listenerOk = new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            String texto = link.getText().toString();
            shareOnFacebook(texto);
            Toast.makeText(getApplicationContext(), "Publicacin compartida correctamente", Toast.LENGTH_SHORT)
                    .show();
        }
    };

    // Creamos un nuevo OnClickListener para el boton Cancelar
    DialogInterface.OnClickListener listenerCancelar = new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            return;
        }
    };

    // Asignamos los botones positivo y negativo a sus respectivos listeners
    //OJO: estan al reves para que sea display si - no en vez de no - si
    alertDialogBuilder.setPositiveButton(R.string.dialogCancel, listenerCancelar);
    alertDialogBuilder.setNegativeButton(R.string.dialogPublish, listenerOk);

    return alertDialogBuilder.create();
}