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:com.newtifry.android.SourceEditor.java

/**
 * Save this source.//from w  w w.  java  2s  . c  o  m
 */
public void save(View view) {
    // User clicked save button.
    // Prepare the new local object.
    this.source = null;
    NewtifrySource source = this.getSource();

    EditText title = (EditText) findViewById(R.id.detail_title);
    source.setTitle(title.getText().toString());

    CheckBox serverEnable = (CheckBox) findViewById(R.id.detail_serverenable);
    source.setServerEnabled(serverEnable.isChecked());
    CheckBox localEnable = (CheckBox) findViewById(R.id.detail_localenable);
    source.setLocalEnabled(localEnable.isChecked());

    // Now, send the updates to the server. On success, save the changes locally.
    BackendRequest request = new BackendRequest("/sources/edit");
    request.add("id", source.getServerId().toString());
    request.add("title", source.getTitle());
    if (source.getServerEnabled()) {
        request.add("enabled", "on");
    }

    request.addMeta("source", source);
    request.addMeta("operation", "save");

    request.setHandler(handler);

    request.startInThread(this, getString(R.string.source_saving_to_server), source.getAccountName());
}

From source file:com.ibm.hellotodo.MainActivity.java

/**
 * Launches a dialog for adding a new TodoItem. Called when plus button is tapped.
 *
 * @param view The plus button that is tapped.
 *///  w  ww  . jav  a 2 s  .  c o m
public void addTodo(View view) {

    final Dialog addDialog = new Dialog(this);

    addDialog.setContentView(R.layout.add_edit_dialog);
    addDialog.setTitle("Add Todo");
    TextView textView = (TextView) addDialog.findViewById(android.R.id.title);
    if (textView != null) {
        textView.setGravity(Gravity.CENTER);
    }

    addDialog.setCancelable(true);
    Button add = (Button) addDialog.findViewById(R.id.Add);
    addDialog.show();

    // When done is pressed, send POST request to create TodoItem on Bluemix
    add.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            EditText itemToAdd = (EditText) addDialog.findViewById(R.id.todo);
            final String name = itemToAdd.getText().toString();
            // If text was added, continue with normal operations
            if (!name.isEmpty()) {

                // Create JSON for new TodoItem, id should be 0 for new items
                String json = "{\"text\":\"" + name + "\",\"isDone\":false,\"id\":0}";

                // Create POST request with IBM Mobile First SDK and set HTTP headers so Bluemix knows what to expect in the request
                Request request = new Request(client.getBluemixAppRoute() + "/api/Items", Request.POST);

                HashMap headers = new HashMap();
                List<String> cType = new ArrayList<>();
                cType.add("application/json");
                List<String> accept = new ArrayList<>();
                accept.add("Application/json");

                headers.put("Content-Type", cType);
                headers.put("Accept", accept);

                request.setHeaders(headers);

                request.send(getApplicationContext(), json, new ResponseListener() {
                    // On success, update local list with new TodoItem
                    @Override
                    public void onSuccess(Response response) {
                        Log.i(TAG, "Item created successfully");

                        loadList();
                    }

                    // On failure, log errors
                    @Override
                    public void onFailure(Response response, Throwable t, JSONObject extendedInfo) {
                        String errorMessage = "";

                        if (response != null) {
                            errorMessage += response.toString() + "\n";
                        }

                        if (t != null) {
                            StringWriter sw = new StringWriter();
                            PrintWriter pw = new PrintWriter(sw);
                            t.printStackTrace(pw);
                            errorMessage += "THROWN" + sw.toString() + "\n";
                        }

                        if (extendedInfo != null) {
                            errorMessage += "EXTENDED_INFO" + extendedInfo.toString() + "\n";
                        }

                        if (errorMessage.isEmpty())
                            errorMessage = "Request Failed With Unknown Error.";

                        Log.e(TAG, "addTodo failed with error: " + errorMessage);
                    }
                });
            }

            // Kill dialog when finished, or if no text was added
            addDialog.dismiss();
        }
    });
}

From source file:most.voip.example.ws_config.MainActivity.java

public void loadConfig(View view) {
    Log.d(TAG, "Starting activity for remote configuration loading...");
    Intent intent = new Intent("most.voip.remote_config.intent.action.Launch");
    EditText txtView = (EditText) this.findViewById(R.id.txtServerIp);
    this.serverIp = txtView.getText().toString();
    intent.putExtra("serverIp", this.serverIp);
    startActivityForResult(intent, REMOTE_ACCOUNT_CONFIG_REQUEST);
}

From source file:most.voip.example.ws_config.MainActivity.java

/**
 * Invoked when the 'Go' button is clicked
 *//*from  ww  w. ja  va 2s.c  o  m*/
public void doVoipTest(View view) {
    EditText txtView = (EditText) this.findViewById(R.id.txtServerIp);
    this.serverIp = txtView.getText().toString();
    InputMethodManager imm = (InputMethodManager) this.getSystemService(Service.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(txtView.getWindowToken(), 0);

    this.runExample();
}

From source file:com.ibm.hellotodo.MainActivity.java

/**
 * Launches a dialog for updating the TodoItem name. Called when the list item is tapped.
 *
 * @param view The TodoItem that is tapped.
 *//*from  w w  w .  j ava2 s  . c om*/
public void editTodoName(View view) {
    // Gets position in list view of tapped item
    final Integer pos = mListView.getPositionForView(view);
    final Dialog addDialog = new Dialog(this);

    addDialog.setContentView(R.layout.add_edit_dialog);
    addDialog.setTitle("Edit Todo");
    TextView textView = (TextView) addDialog.findViewById(android.R.id.title);
    if (textView != null) {
        textView.setGravity(Gravity.CENTER);
    }
    addDialog.setCancelable(true);
    EditText et = (EditText) addDialog.findViewById(R.id.todo);

    final String name = mTodoItemList.get(pos).text;
    final boolean isDone = mTodoItemList.get(pos).isDone;
    final int id = mTodoItemList.get(pos).idNumber;
    et.setText(name);

    Button addDone = (Button) addDialog.findViewById(R.id.Add);
    addDialog.show();

    // When done is pressed, send PUT request to update TodoItem on Bluemix
    addDone.setOnClickListener(new View.OnClickListener() {
        // Save text inputted when done is tapped
        @Override
        public void onClick(View view) {
            EditText editedText = (EditText) addDialog.findViewById(R.id.todo);

            String newName = editedText.getText().toString();

            // If new text is not empty, create JSON with updated info and send PUT request
            if (!newName.isEmpty()) {
                String json = "{\"text\":\"" + newName + "\",\"isDone\":" + isDone + ",\"id\":" + id + "}";

                // Create PUT REST request using the IBM Mobile First SDK and set HTTP headers so Bluemix knows what to expect in the request
                Request request = new Request(client.getBluemixAppRoute() + "/api/Items", Request.PUT);

                HashMap headers = new HashMap();
                List<String> cType = new ArrayList<>();
                cType.add("application/json");
                List<String> accept = new ArrayList<>();
                accept.add("Application/json");

                headers.put("Content-Type", cType);
                headers.put("Accept", accept);

                request.setHeaders(headers);

                request.send(getApplicationContext(), json, new ResponseListener() {
                    // On success, update local list with updated TodoItem
                    @Override
                    public void onSuccess(Response response) {
                        Log.i(TAG, "Item updated successfully");

                        loadList();
                    }

                    // On failure, log errors
                    @Override
                    public void onFailure(Response response, Throwable t, JSONObject extendedInfo) {
                        String errorMessage = "";

                        if (response != null) {
                            errorMessage += response.toString() + "\n";
                        }

                        if (t != null) {
                            StringWriter sw = new StringWriter();
                            PrintWriter pw = new PrintWriter(sw);
                            t.printStackTrace(pw);
                            errorMessage += "THROWN" + sw.toString() + "\n";
                        }

                        if (extendedInfo != null) {
                            errorMessage += "EXTENDED_INFO" + extendedInfo.toString() + "\n";
                        }

                        if (errorMessage.isEmpty())
                            errorMessage = "Request Failed With Unknown Error.";

                        Log.e(TAG, "editTodoName failed with error: " + errorMessage);
                    }
                });

            }
            addDialog.dismiss();
        }
    });
}

From source file:palamarchuk.smartlife.app.RegisterActivity.java

private boolean checkSize(EditText editText, int min, int max) {
    int length = editText.getText().toString().length();
    return length < min || length > max;
}

From source file:most.voip.example.ws_config.MainActivity.java

public void makeCall(View view) {
    EditText txtExtension = (EditText) this.findViewById(R.id.txtExtension);
    String extension = txtExtension.getText().toString();
    this.myVoip.makeCall(extension);
}

From source file:com.shalzz.attendance.activity.LoginActivity.java

@Override
public void onDialogPositiveClick(DialogFragment dialog) {

    Dialog dialogView = dialog.getDialog();
    final EditText Captxt = (EditText) dialogView.findViewById(R.id.etCapTxt);

    if (data.isEmpty())
        getHiddenData();//  ww  w. j a v  a 2s.  c  om

    // workaround for enrollment number.
    String sapid = etSapid.getText().toString();
    if (sapid.length() == 10 && sapid.charAt(0) == '#')
        sapid = sapid.replaceFirst("#", "R");

    new UserAccount(LoginActivity.this).Login(sapid, etPass.getText().toString(), Captxt.getText().toString(),
            data);
    Miscellaneous.closeKeyboard(this, Captxt);
    dialog.dismiss();
}

From source file:org.elasticdroid.SshConnectorView.java

@Override
public void onClick(View button) {
    switch (button.getId()) {
    case R.id.sshConnectorLoginButton:
        EditText usernameEditText = (EditText) findViewById(R.id.sshConnectorUsernameEditTextView);

        //if no user name entered, do not proceed; warn user and exit
        if (usernameEditText.getText().toString().trim().equals("")) {
            usernameEditText.setError(getString(R.string.loginview_invalid_username_err));
        } else {/*from w  w w.jav a 2 s .co  m*/
            executeSshConnectorModel();//execute the SSH connector model
        }
        break;
    }
}

From source file:com.jdom.get.stuff.done.android.AndroidApplicationContextFactory.java

public void getTextInputForAction(String title, String hintText, String doButtonText, String dontButtonText,
        final RunnableWithResults<String> callback) {

    final EditText textView = new EditText(activity);
    textView.setHint(hintText);//w w  w . j a v  a  2 s  .  c  o  m

    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setView(textView);
    builder.setTitle(title);
    builder.setCancelable(false).setPositiveButton(doButtonText, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            callback.callback(textView.getText().toString());
        }
    }).setNegativeButton(dontButtonText, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
        }
    });
    builder.show();

}