Example usage for android.widget EditText getText

List of usage examples for android.widget EditText getText

Introduction

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

Prototype

@Override
    public Editable getText() 

Source Link

Usage

From source file:at.alladin.rmbt.android.about.RMBTAboutFragment.java

private void handleHiddenCode() {
    if (++developerFeatureCounter >= 10) {
        developerFeatureCounter = 0;//  ww w.j a  v  a  2 s. com
        final EditText input = new EditText(getActivity());
        input.setInputType(InputType.TYPE_CLASS_NUMBER);
        final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setView(input);
        builder.setTitle(R.string.about_hidden_feature_dialog_title);
        builder.setMessage(R.string.about_hidden_feature_dialog_enter_code);
        builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
            @Override
            public void onClick(final DialogInterface dialog, final int which) {

                try {
                    final String data = input.getText().toString();
                    if (!data.matches("\\d{8}")) {
                        Toast.makeText(getActivity(), R.string.about_hidden_feature_dialog_msg_try_again,
                                Toast.LENGTH_LONG).show();
                        return;
                    }

                    final int dataInt = Integer.parseInt(data);
                    if (dataInt == 0) // deactivate all features
                    {
                        ConfigHelper.setUserLoopModeState(getActivity(), false);
                        ConfigHelper.setDevModeState(getActivity(), false);
                        ConfigHelper.setServerSelectionState(getActivity(), false);
                        ((RMBTMainActivity) getActivity()).checkSettings(true, null); // refresh server list
                        Toast.makeText(getActivity(), R.string.about_hidden_feature_dialog_msg_deactivated,
                                Toast.LENGTH_LONG).show();
                        return;
                    }

                    if (ConfigHelper.isValidCheckSum(dataInt)) { // developer mode
                        if (dataInt == AppConstants.DEVELOPER_UNLOCK_CODE) {
                            ConfigHelper.setDevModeState(getActivity(), true);
                            Toast.makeText(getActivity(), R.string.about_dev_mode_activated, Toast.LENGTH_LONG)
                                    .show();
                        } else if (dataInt == AppConstants.DEVELOPER_LOCK_CODE) {
                            ConfigHelper.setDevModeState(getActivity(), false);
                            Toast.makeText(getActivity(), R.string.about_dev_mode_deactivated,
                                    Toast.LENGTH_LONG).show();
                        }
                        // loop mode
                        else if (dataInt == AppConstants.LOOP_MODE_UNLOCK_CODE) {
                            ConfigHelper.setUserLoopModeState(getActivity(), true);
                            Toast.makeText(getActivity(), R.string.about_loop_mode_activated, Toast.LENGTH_LONG)
                                    .show();
                        } else if (dataInt == AppConstants.LOOP_MODE_LOCK_CODE) {
                            ConfigHelper.setUserLoopModeState(getActivity(), false);
                            Toast.makeText(getActivity(), R.string.about_loop_mode_deactivated,
                                    Toast.LENGTH_LONG).show();
                        }
                        // server selection
                        else if (dataInt == AppConstants.SERVER_SELECTION_UNLOCK_CODE) {
                            ConfigHelper.setServerSelectionState(getActivity(), true);
                            ((RMBTMainActivity) getActivity()).checkSettings(true, null); // refresh server list
                            Toast.makeText(getActivity(), R.string.about_server_selection_activated,
                                    Toast.LENGTH_LONG).show();
                        } else if (dataInt == AppConstants.SERVER_SELECTION_LOCK_CODE) {
                            ConfigHelper.setServerSelectionState(getActivity(), false);
                            ((RMBTMainActivity) getActivity()).checkSettings(true, null); // refresh server list
                            Toast.makeText(getActivity(), R.string.about_server_selection_deactivated,
                                    Toast.LENGTH_LONG).show();
                        }
                        // code not used
                        else {
                            Toast.makeText(getActivity(), R.string.about_hidden_feature_dialog_msg_try_again,
                                    Toast.LENGTH_LONG).show();
                        }
                    } else
                        Toast.makeText(getActivity(), R.string.about_hidden_feature_dialog_msg_try_again,
                                Toast.LENGTH_LONG).show();
                } catch (Exception e) // ignore errors
                {
                    e.printStackTrace();
                }
            }
        });
        builder.setNegativeButton(android.R.string.cancel, null);

        dialog = builder.create();
        dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
        dialog.show();
    }
}

From source file:com.mendhak.gpslogger.common.PrefsIO.java

public void AskFileName() {

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(R.string.AskFileName);

    final EditText input = new EditText(context);
    input.setInputType(InputType.TYPE_CLASS_TEXT);

    int pos = curFileName.lastIndexOf(File.separator) + 1;
    String filename = "";
    if (pos > 0)
        filename = curFileName.substring(pos);
    pos = filename.lastIndexOf(extension);
    if (pos > 1)
        input.setText(filename.substring(0, pos - 1));
    else//from   w  w w . j  av  a  2 s.c  o m
        input.setText(defFileName);

    Utilities.LogDebug("Asking user the filename to use for export of settings");

    builder.setView(input);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            String str = input.getText().toString();
            String fname = "";
            if (str.length() > 0)
                fname = str.replaceAll(filter, "");
            if (fname.length() != 0) {
                curFileName = defPath + File.separator + fname + "." + extension;
                ExportFile();
            }
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });

    builder.show();
}

From source file:com.snappy.VoiceActivity.java

private void setInitComments() {
    // for comment
    // **********************************************
    mLvComments = (ListView) findViewById(R.id.lvPhotoComments);
    mLvComments.setCacheColorHint(0);/*ww w  .  ja  v  a2s . c o m*/

    final EditText etComment = (EditText) findViewById(R.id.etComment);
    etComment.setTypeface(SpikaApp.getTfMyriadPro());

    mMessage = (Message) getIntent().getSerializableExtra("message");

    mComments = new ArrayList<Comment>();

    new GetCommentsAsync(VoiceActivity.this, mMessage, mComments, mCommentsAdapter, mLvComments, true)
            .execute(mMessage.getId());
    scrollListViewToBottom();

    Button btnSendComment = (Button) findViewById(R.id.btnSendComment);
    btnSendComment.setTypeface(SpikaApp.getTfMyriadProBold(), Typeface.BOLD);

    btnSendComment.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            String commentText = etComment.getText().toString();
            if (!commentText.equals("")) {
                Comment comment = CommentManagement.createComment(commentText, mMessage.getId());
                scrollListViewToBottom();

                CouchDB.createCommentAsync(comment, new CreateCommentFinish(), VoiceActivity.this, true);

                etComment.setText("");
                Utils.hideKeyboard(VoiceActivity.this);

            }

        }
    });

    // **********************************************
}

From source file:com.vkassin.mtrade.Common.java

public static void putOrder(final Context ctx, Quote quote) {

    final Instrument it = Common.selectedInstrument;// adapter.getItem(selectedRowId);

    final Dialog dialog = new Dialog(ctx);
    dialog.setContentView(R.layout.order_dialog);
    dialog.setTitle(R.string.OrderDialogTitle);

    datetxt = (EditText) dialog.findViewById(R.id.expdateedit);
    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
    Date dat1 = new Date();
    datetxt.setText(sdf.format(dat1));//from w w w. j a  v  a  2  s  .c o m
    mYear = dat1.getYear() + 1900;
    mMonth = dat1.getMonth();
    mDay = dat1.getDate();
    final Date dat = new GregorianCalendar(mYear, mMonth, mDay).getTime();

    datetxt.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Log.i(TAG, "Show DatePickerDialog");
            DatePickerDialog dpd = new DatePickerDialog(ctx, mDateSetListener, mYear, mMonth, mDay);
            dpd.show();
        }
    });

    TextView itext = (TextView) dialog.findViewById(R.id.instrtext);
    itext.setText(it.symbol);

    final Spinner aspinner = (Spinner) dialog.findViewById(R.id.acc_spinner);
    List<String> list = new ArrayList<String>(Common.getAccountList());
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(Common.app_ctx,
            android.R.layout.simple_spinner_item, list);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
    aspinner.setAdapter(dataAdapter);

    final EditText pricetxt = (EditText) dialog.findViewById(R.id.priceedit);
    final EditText quanttxt = (EditText) dialog.findViewById(R.id.quantedit);

    final Button buttonpm = (Button) dialog.findViewById(R.id.buttonPriceMinus);
    buttonpm.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            try {

                double price = Double.valueOf(pricetxt.getText().toString());
                price -= 0.01;
                if (price < 0)
                    price = 0;
                pricetxt.setText(twoDForm.format(price));

            } catch (Exception e) {

                Toast.makeText(ctx, R.string.CorrectPrice, Toast.LENGTH_SHORT).show();
            }
        }
    });

    final Button buttonpp = (Button) dialog.findViewById(R.id.buttonPricePlus);
    buttonpp.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            try {

                double price = Double.valueOf(pricetxt.getText().toString());
                price += 0.01;
                pricetxt.setText(twoDForm.format(price));

            } catch (Exception e) {

                Toast.makeText(ctx, R.string.CorrectPrice, Toast.LENGTH_SHORT).show();
            }
        }
    });

    final Button buttonqm = (Button) dialog.findViewById(R.id.buttonQtyMinus);
    buttonqm.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            try {

                long qty = Long.valueOf(quanttxt.getText().toString());
                qty -= 1;
                if (qty < 0)
                    qty = 0;
                quanttxt.setText(String.valueOf(qty));

            } catch (Exception e) {

                Toast.makeText(ctx, R.string.CorrectQty, Toast.LENGTH_SHORT).show();
            }
        }
    });

    final Button buttonqp = (Button) dialog.findViewById(R.id.buttonQtyPlus);
    buttonqp.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            try {

                long qty = Long.valueOf(quanttxt.getText().toString());
                qty += 1;
                quanttxt.setText(String.valueOf(qty));

            } catch (Exception e) {

                Toast.makeText(ctx, R.string.CorrectQty, Toast.LENGTH_SHORT).show();
            }
        }
    });

    final RadioButton bu0 = (RadioButton) dialog.findViewById(R.id.radio0);
    final RadioButton bu1 = (RadioButton) dialog.findViewById(R.id.radio1);

    if (quote != null) {

        // pricetxt.setText(quote.price.toString());
        pricetxt.setText(quote.getPriceS());
        if (quote.qtyBuy > 0) {

            quanttxt.setText(quote.qtyBuy.toString());
            bu1.setChecked(true);
            bu0.setChecked(false);

        } else {

            quanttxt.setText(quote.qtySell.toString());
            bu1.setChecked(false);
            bu0.setChecked(true);

        }
    }

    Button customDialog_Cancel = (Button) dialog.findViewById(R.id.cancelbutt);
    customDialog_Cancel.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View arg0) {

            dialog.dismiss();
        }

    });

    Button customDialog_Put = (Button) dialog.findViewById(R.id.putorder);
    customDialog_Put.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View arg0) {

            Double price = new Double(0);
            Long qval = new Long(0);

            try {

                price = Double.valueOf(pricetxt.getText().toString());
            } catch (Exception e) {

                Toast.makeText(ctx, R.string.CorrectPrice, Toast.LENGTH_SHORT).show();
                return;
            }
            try {

                qval = Long.valueOf(quanttxt.getText().toString());
            } catch (Exception e) {

                Toast.makeText(ctx, R.string.CorrectQty, Toast.LENGTH_SHORT).show();
                return;
            }

            if (dat.compareTo(new GregorianCalendar(mYear, mMonth, mDay).getTime()) > 0) {

                Toast.makeText(ctx, R.string.CorrectDate, Toast.LENGTH_SHORT).show();

                return;

            }

            JSONObject msg = new JSONObject();
            try {

                msg.put("objType", Common.CREATE_REMOVE_ORDER);
                msg.put("time", Calendar.getInstance().getTimeInMillis());
                msg.put("version", Common.PROTOCOL_VERSION);
                msg.put("device", "Android");
                msg.put("instrumId", Long.valueOf(it.id));
                msg.put("price", price);
                msg.put("qty", qval);
                msg.put("ordType", 1);
                msg.put("side", bu0.isChecked() ? 0 : 1);
                msg.put("code", String.valueOf(aspinner.getSelectedItem()));
                msg.put("orderNum", ++ordernum);
                msg.put("action", "CREATE");
                boolean b = (((mYear - 1900) == dat.getYear()) && (mMonth == dat.getMonth())
                        && (mDay == dat.getDate()));
                if (!b)
                    msg.put("expired", String.format("%02d.%02d.%04d", mDay, mMonth + 1, mYear));

                if (isSSL) {

                    //                ? ?:    newOrder-orderNum-instrumId-side-price-qty-code-ordType
                    //               :                  newOrder-16807-20594623-0-1150-13-1027700451-1
                    String forsign = "newOrder-" + ordernum + "-" + msg.getString("instrumId") + "-"
                            + msg.getString("side") + "-"
                            + JSONObject.numberToString(Double.valueOf(msg.getDouble("price"))) + "-"
                            + msg.getString("qty") + "-" + msg.getString("code") + "-"
                            + msg.getString("ordType");
                    byte[] signed = Common.signText(Common.signProfile, forsign.getBytes(), true);
                    String gsign = Base64.encodeToString(signed, Base64.DEFAULT);
                    msg.put("gostSign", gsign);
                }
                mainActivity.writeJSONMsg(msg);

            } catch (Exception e) {

                e.printStackTrace();
                Log.e(TAG, "Error! Cannot create JSON order object", e);
            }

            dialog.dismiss();
        }

    });

    dialog.show();

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(dialog.getWindow().getAttributes());
    lp.width = WindowManager.LayoutParams.FILL_PARENT;
    lp.height = WindowManager.LayoutParams.FILL_PARENT;
    dialog.getWindow().setAttributes(lp);

}

From source file:fm.libre.droid.LibreDroid.java

/** Called when the activity is first created. */
@Override// w  w  w. j a  va  2s . com
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    libreServiceConn = new LibreServiceConnection();
    bindService(new Intent(this, LibreService.class), libreServiceConn, Context.BIND_AUTO_CREATE);

    this.registerReceiver(new MediaButtonReceiver(), new IntentFilter(Intent.ACTION_MEDIA_BUTTON));
    this.registerReceiver(new UIUpdateReceiver(), new IntentFilter("LibreDroidNewSong"));
    setContentView(R.layout.main);

    // Load settings
    final SharedPreferences settings = getSharedPreferences("LibreDroid", MODE_PRIVATE);
    username = settings.getString("Username", "");
    password = settings.getString("Password", "");

    final EditText usernameEntry = (EditText) findViewById(R.id.usernameEntry);
    final EditText passwordEntry = (EditText) findViewById(R.id.passwordEntry);
    usernameEntry.setText(username);
    passwordEntry.setText(password);

    final Button loginButton = (Button) findViewById(R.id.loginButton);
    loginButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Editor editor = settings.edit();
            editor.putString("Username", usernameEntry.getText().toString());
            editor.putString("Password", passwordEntry.getText().toString());
            editor.commit();

            LibreDroid.this.login();
        }
    });

    stations = new ArrayList<String>();
    try {
        BufferedReader stationReader = new BufferedReader(
                new InputStreamReader(openFileInput("libredroid-custom-stations.conf")));
        String station;
        while ((station = stationReader.readLine()) != null) {
            stations.add(station);
        }
        stationReader.close();
    } catch (IOException ex) {
        Log.d("libredroid", ex.getMessage());
    }
    // Add default stations if empty
    if (stations.isEmpty()) {
        String radioButtons[] = { "Folk", "Rock", "Metal", "Classical", "Pop", "Punk", "Jazz", "Blues", "Rap",
                "Ambient", "Add A Custom Station..." };
        stations.addAll(Arrays.asList(radioButtons));
    }
    setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, stations));

    Button tagStation = (Button) findViewById(R.id.tagStationButton);
    tagStation.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            LibreDroid.this.nextPage();
        }
    });

    Button loveStation = (Button) findViewById(R.id.loveStationButton);
    loveStation.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            LibreDroid.this.libreServiceConn.service.tuneStation("user", username + "/loved");
            LibreDroid.this.nextPage();
            LibreDroid.this.nextPage();
            LibreDroid.this.nextPage();
        }
    });

    Button communityLoveStation = (Button) findViewById(R.id.communityStationButton);
    communityLoveStation.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            LibreDroid.this.libreServiceConn.service.tuneStation("community", "loved");
            LibreDroid.this.nextPage();
            LibreDroid.this.nextPage();
            LibreDroid.this.nextPage();
        }
    });

    final ImageButton nextButton = (ImageButton) findViewById(R.id.nextButton);
    nextButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            LibreDroid.this.libreServiceConn.service.next();
        }
    });
    final ImageButton prevButton = (ImageButton) findViewById(R.id.prevButton);
    prevButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            LibreDroid.this.libreServiceConn.service.prev();
        }
    });
    final ImageButton playPauseButton = (ImageButton) findViewById(R.id.playPauseButton);
    playPauseButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            LibreDroid.this.togglePause();
        }
    });
    final ImageButton saveButton = (ImageButton) findViewById(R.id.saveButton);
    saveButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            LibreDroid.this.save();
        }
    });
    final ImageButton loveButton = (ImageButton) findViewById(R.id.loveButton);
    loveButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            LibreDroid.this.libreServiceConn.service.love();
        }
    });
    final ImageButton banButton = (ImageButton) findViewById(R.id.banButton);
    banButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            LibreDroid.this.libreServiceConn.service.ban();
        }
    });
    final Button addStationButton = (Button) findViewById(R.id.addStationButton);
    addStationButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            LibreDroid.this.addStation();
        }
    });
}

From source file:com.openerp.addons.messages.MessageComposeActivty.java

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

    case android.R.id.home:
        // app icon in action bar clicked; go home
        finish();/*from w  w  w .j  a va  2  s .  c  o  m*/
        return true;
    case R.id.menu_message_compose_add_attachment_images:
        requestForAttachmentIntent(ATTACHMENT_TYPE.IMAGE);
        return true;
    case R.id.menu_message_compose_add_attachment_files:
        requestForAttachmentIntent(ATTACHMENT_TYPE.TEXT_FILE);
        return true;
    //??
    case R.id.menu_message_compose_send:

        EditText edtSubject = (EditText) findViewById(R.id.edtMessageSubject);
        EditText edtBody = (EditText) findViewById(R.id.edtMessageBody);
        edtSubject.setError(null);
        edtBody.setError(null);
        if (selectedPartners.size() == 0) {
            Toast.makeText(this, "", Toast.LENGTH_LONG).show();
        } else if (TextUtils.isEmpty(edtSubject.getText())) {
            edtSubject.setError("? !");
        } else if (TextUtils.isEmpty(edtBody.getText())) {
            edtBody.setError("?!");
        } else {

            Toast.makeText(this, "??...", Toast.LENGTH_LONG).show();
            String subject = edtSubject.getText().toString();
            String body = edtBody.getText().toString();
            //oe?
            Ir_AttachmentDBHelper attachment = new Ir_AttachmentDBHelper(MainActivity.context);
            JSONArray newAttachmentIds = new JSONArray();
            for (Uri file : file_uris) {
                // oe?????
                File fileData = new File(file.getPath());
                ContentValues values = new ContentValues();
                values.put("datas_fname", getFilenameFromUri(file));
                values.put("res_model", "mail.compose.message");
                values.put("company_id", scope.User().getCompany_id());
                values.put("type", "binary");
                values.put("res_id", 0);
                values.put("file_size", fileData.length());
                values.put("db_datas", Base64Helper.fileUriToBase64(file, getContentResolver()));
                values.put("name", getFilenameFromUri(file));
                int newId = attachment.create(attachment, values);
                newAttachmentIds.put(newId);
            }

            // TASK: sending mail
            HashMap<String, Object> values = new HashMap<String, Object>();
            values.put("subject", subject);
            if (is_note_body) {
                values.put("body", Html.toHtml(edtBody.getText()));
            } else {
                values.put("body", body);
            }
            values.put("partner_ids", getPartnersId());
            values.put("attachment_ids", newAttachmentIds);

            if (is_reply) {
                SendMailMessageReply sendMessageRply = new SendMailMessageReply(values);
                sendMessageRply.execute((Void) null);
            } else {
                SendMailMessage sendMessage = new SendMailMessage(values);
                sendMessage.execute((Void) null);
            }

        }
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.orange.ocara.ui.activity.SetupAuditPathActivity.java

private void updateAuditObject(final AuditObject auditObject) {

    // Use an EditText view to get user input.
    final EditText input = new EditText(this);
    input.setText(auditObject.getName());

    AlertDialog updateDialog = new OcaraDialogBuilder(this)
            .setTitle(com.orange.ocara.R.string.audit_object_update_object_title) // title
            .setView(input).setPositiveButton(com.orange.ocara.R.string.audit_object_update_object_button,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            String name = input.getText().toString();

                            if (StringUtils.isNotBlank(name)) {
                                updateAuditObjectName(auditObject, name);
                            }/*from  w  w  w.ja v a2 s  .com*/
                        }
                    })
            .setNegativeButton(com.orange.ocara.R.string.action_cancel, null).create();

    updateDialog.show();
}

From source file:com.bti360.hackathon.listview.HackathonActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case ADD_DIALOG:
        // We are going to create an AlertDialog with a single text input and a button
        // first we create the EditText
        final EditText edit = new EditText(this);
        // Next we create an AlertDialog.Builder which creates a styled AlertDialog based
        // on our specifications;
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        // set the title
        builder.setTitle("Add Person");
        // set the icon to a built-in, this one is a +
        builder.setIcon(android.R.drawable.ic_input_add);
        // set the text of the only button, and add a click listener
        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {

            @Override/*w  w w. jav a  2s  .c om*/
            public void onClick(DialogInterface dialog, int which) {
                // on the Ok Button we grab the text from the EditText,
                // clear it and then add the Name to our list
                String name = edit.getText().toString();
                edit.setText("");
                addName(name);
            }
        });
        // finally let's create the dialog
        final AlertDialog d = builder.create();
        // and set the view to our EditText
        d.setView(edit);

        // we'll set a special InputType since we are collecting a name
        // other's exist such as email, address, phone number, etc
        // this allows the IME (keyboard) to customize itself based on
        // expected input, e.g. show @ and .com when Email
        edit.setInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME);
        // Respond to the default action on the IME (keyboard) By default it is
        // "Done" but it can be changed with setImeActionLabel to be something
        // else like a search hourglass.
        // In our case we want a click on "Done" to do the same thing as a click
        // on the Ok button in the Dialog.
        edit.setOnEditorActionListener(new OnEditorActionListener() {

            @Override
            public boolean onEditorAction(TextView tv, int actionId, KeyEvent arg2) {
                // same as the DialogClick Handler except we also dismiss the dialog
                String name = edit.getText().toString();
                edit.setText("");
                addName(name);
                d.dismiss();
                return true;
            }
        });
        return d;
    }
    return super.onCreateDialog(id);
}

From source file:com.google.sample.beaconservice.ManageBeaconFragment.java

private View.OnClickListener makeInsertAttachmentOnClickListener(final Button insertButton,
        final TextView namespaceTextView, final EditText typeEditText, final EditText dataEditText) {
    return new View.OnClickListener() {
        @Override// w  w w.  j  a v  a  2s  .  co  m
        public void onClick(View v) {
            final String namespace = namespaceTextView.getText().toString();
            if (namespace.length() == 0) {
                toast("namespace cannot be empty");
                return;
            }
            final String type = typeEditText.getText().toString();
            if (type.length() == 0) {
                toast("type cannot be empty");
                return;
            }
            final String data = dataEditText.getText().toString();
            if (data.length() == 0) {
                toast("data cannot be empty");
                return;
            }

            Utils.setEnabledViews(false, insertButton);
            JSONObject body = buildCreateAttachmentJsonBody(namespace, type, data);

            Callback createAttachmentCallback = new Callback() {
                @Override
                public void onFailure(Request request, IOException e) {
                    logErrorAndToast("Failed request: " + request, e);
                    Utils.setEnabledViews(false, insertButton);
                }

                @Override
                public void onResponse(Response response) throws IOException {
                    String body = response.body().string();
                    if (response.isSuccessful()) {
                        try {
                            JSONObject json = new JSONObject(body);
                            attachmentsTable.addView(makeAttachmentRow(json), 2);
                            namespaceTextView.setText(namespace);
                            typeEditText.setText("");
                            typeEditText.requestFocus();
                            dataEditText.setText("");
                            insertButton.setEnabled(true);
                        } catch (JSONException e) {
                            logErrorAndToast("JSONException in building attachment data", e);
                        }
                    } else {
                        logErrorAndToast("Unsuccessful createAttachment request: " + body);
                    }
                    Utils.setEnabledViews(true, insertButton);
                }
            };

            client.createAttachment(createAttachmentCallback, beacon.getBeaconName(), body);
        }
    };
}