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:de.baumann.hhsmoodle.activities.Activity_count.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    PreferenceManager.setDefaultValues(this, R.xml.user_settings, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    toDo_title = sharedPref.getString("count_title", "");
    String count_title = sharedPref.getString("count_content", "");
    toDo_icon = sharedPref.getString("count_icon", "");
    toDo_create = sharedPref.getString("count_create", "");
    String todo_attachment = sharedPref.getString("count_attachment", "");
    if (!sharedPref.getString("count_seqno", "").isEmpty()) {
        toDo_seqno = Integer.parseInt(sharedPref.getString("count_seqno", ""));
    }/*w  w  w .java 2s .c  om*/

    setContentView(R.layout.activity_count);
    setTitle(toDo_title);

    final EditText etNewItem = (EditText) findViewById(R.id.etNewItem);
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            String itemText = etNewItem.getText().toString();

            if (itemText.isEmpty()) {
                Snackbar.make(lvItems, R.string.todo_enter, Snackbar.LENGTH_LONG).show();
            } else {
                itemsTitle.add(0, itemText);
                itemsCount.add(0, "0");
                etNewItem.setText("");
                writeItemsTitle();
                writeItemsCount();
                lvItems.post(new Runnable() {
                    public void run() {
                        lvItems.setSelection(lvItems.getCount() - 1);
                    }
                });
                adapter.notifyDataSetChanged();
            }
        }
    });

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    helper_main.onStart(Activity_count.this);

    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    try {
        FileOutputStream fOut = new FileOutputStream(newFileTitle());
        OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
        myOutWriter.append(count_title);
        myOutWriter.close();

        fOut.flush();
        fOut.close();
    } catch (IOException e) {
        Log.e("Exception", "File write failed: " + e.toString());
    }

    try {
        FileOutputStream fOut = new FileOutputStream(newFileCount());
        OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
        myOutWriter.append(todo_attachment);
        myOutWriter.close();

        fOut.flush();
        fOut.close();
    } catch (IOException e) {
        Log.e("Exception", "File write failed: " + e.toString());
    }

    lvItems = (ListView) findViewById(R.id.lvItems);
    itemsTitle = new ArrayList<>();
    readItemsTitle();
    readItemsCount();

    adapter = new CustomListAdapter(Activity_count.this, itemsTitle, itemsCount) {
        @NonNull
        @Override
        public View getView(final int position, View convertView, @NonNull ViewGroup parent) {

            View v = super.getView(position, convertView, parent);
            ImageButton ib_plus = (ImageButton) v.findViewById(R.id.but_plus);
            ImageButton ib_minus = (ImageButton) v.findViewById(R.id.but_minus);
            TextView tv = (TextView) v.findViewById(R.id.count_count);

            int count = Integer.parseInt(itemsCount.get(position));

            if (count < 0) {
                tv.setTextColor(ContextCompat.getColor(Activity_count.this, R.color.color_red));
            } else if (count > 0) {
                tv.setTextColor(ContextCompat.getColor(Activity_count.this, R.color.color_green));
            } else if (count == 0) {
                tv.setTextColor(ContextCompat.getColor(Activity_count.this, R.color.color_grey));
            }

            ib_plus.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    int a = Integer.parseInt(itemsCount.get(position)) + 1;
                    String plus = String.valueOf(a);

                    itemsCount.remove(position);
                    itemsCount.add(position, plus);
                    // Refresh the adapter
                    adapter.notifyDataSetChanged();
                    // Return true consumes the long click event (marks it handled)
                    writeItemsTitle();
                    writeItemsCount();

                }
            });

            ib_minus.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    int a = Integer.parseInt(itemsCount.get(position)) - 1;
                    String minus = String.valueOf(a);

                    itemsCount.remove(position);
                    itemsCount.add(position, minus);
                    // Refresh the adapter
                    adapter.notifyDataSetChanged();
                    // Return true consumes the long click event (marks it handled)
                    writeItemsTitle();
                    writeItemsCount();
                }
            });

            return v;
        }
    };

    lvItems.setAdapter(adapter);

    lvItems.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(android.widget.AdapterView<?> parent, View view, final int position, long id) {

            final String title = itemsTitle.get(position);
            final String count = itemsCount.get(position);

            AlertDialog.Builder builder = new AlertDialog.Builder(Activity_count.this);
            View dialogView = View.inflate(Activity_count.this, R.layout.dialog_edit_text_singleline_count,
                    null);

            final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title);
            edit_title.setText(title);

            builder.setView(dialogView);
            builder.setTitle(R.string.number_edit_entry);
            builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {

                    String inputTag = edit_title.getText().toString().trim();
                    // Remove the item within array at position
                    itemsTitle.remove(position);
                    itemsCount.remove(position);

                    itemsTitle.add(position, inputTag);
                    itemsCount.add(position, count);

                    // Refresh the adapter
                    adapter.notifyDataSetChanged();
                    // Return true consumes the long click event (marks it handled)
                    writeItemsTitle();
                    writeItemsCount();
                }
            });
            builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.cancel();
                }
            });

            final AlertDialog dialog2 = builder.create();
            // Display the custom alert dialog on interface
            dialog2.show();
            helper_main.showKeyboard(Activity_count.this, edit_title);
        }
    });

    lvItems.setOnItemLongClickListener(new android.widget.AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(android.widget.AdapterView<?> parent, View view, final int position,
                long id) {

            final String title = itemsTitle.get(position);
            final String count = itemsCount.get(position);

            // Remove the item within array at position
            itemsTitle.remove(position);
            itemsCount.remove(position);
            // Refresh the adapter
            adapter.notifyDataSetChanged();
            // Return true consumes the long click event (marks it handled)
            writeItemsTitle();
            writeItemsCount();

            Snackbar snackbar = Snackbar.make(lvItems, R.string.todo_removed, Snackbar.LENGTH_LONG)
                    .setAction(R.string.todo_removed_back, new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            itemsTitle.add(position, title);
                            itemsCount.add(position, count);
                            // Refresh the adapter
                            adapter.notifyDataSetChanged();
                            // Return true consumes the long click event (marks it handled)
                            writeItemsTitle();
                            writeItemsCount();
                        }
                    });
            snackbar.show();

            return true;
        }
    });
}

From source file:org.pixmob.appengine.client.demo.DemoActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    if (NO_ACCOUNT_DIALOG == id) {
        final AlertDialog d = new AlertDialog.Builder(this).setTitle(R.string.error).setCancelable(false)
                .setMessage(R.string.no_account_error).setPositiveButton(R.string.quit, new OnClickListener() {
                    @Override// w w w.  j  a v  a2 s .c  om
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                    }
                }).create();
        return d;
    }
    if (PROGRESS_DIALOG == id) {
        final ProgressDialog d = new ProgressDialog(this);
        d.setMessage(getString(R.string.connecting_to_appengine));
        d.setOnCancelListener(new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                loginTask.cancel(true);
                // release resources when the task is canceled
                loginTask = null;
            }
        });
        return d;
    }
    if (MODIFY_APPSPOT_BASE_DIALOG == id) {
        final EditText input = new EditText(this);
        input.setSelectAllOnFocus(true);
        input.setText(prefs.getString(APPSPOT_BASE_PREF, defaultAppspotBase));
        final AlertDialog d = new AlertDialog.Builder(this).setView(input)
                .setTitle(R.string.enter_appspot_instance_name)
                .setPositiveButton(R.string.ok, new OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        appspotBase = trimToNull(input.getText().toString());
                        if (appspotBase == null) {
                            appspotBase = defaultAppspotBase;
                        }
                        appspotBaseView.setText(appspotBase);
                        storeFields();
                    }
                }).create();
        return d;
    }

    return super.onCreateDialog(id);
}

From source file:org.yaoha.YaohaActivity.java

private void openFavMenu(final ImageButton btn, final TextView tv) {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    final EditText input = new EditText(this);
    alert.setTitle("Adding favorite");
    alert.setMessage("Enter your favorite search");
    alert.setView(input);/*from   w  w w.  j  a va 2s  .c o  m*/

    alert.setPositiveButton("Set", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            final Editor edit = prefs.edit();
            String tmp = "";
            tv.setText(input.getText());
            btn.setImageResource(R.drawable.placeholder_logo);
            if (btn.getId() == button_favorite_1.getId()) {
                tmp = "saved_fav_1_text";
            } else if (btn.getId() == button_favorite_2.getId()) {
                tmp = "saved_fav_2_text";
            } else if (btn.getId() == button_favorite_3.getId()) {
                tmp = "saved_fav_3_text";
            } else if (btn.getId() == button_favorite_4.getId()) {
                tmp = "saved_fav_4_text";
            } else if (btn.getId() == button_favorite_5.getId()) {
                tmp = "saved_fav_5_text";
            } else if (btn.getId() == button_favorite_6.getId()) {
                tmp = "saved_fav_6_text";
            }
            edit.putString(tmp, input.getText().toString());
            edit.commit();
            //TODO add method to catch pre-defined store-icons
        }
    });

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

From source file:com.manzdagratiano.gobbledygook.Gobbledygook.java

/**
 * @brief   /*from ww w. j av a 2 s .c  om*/
 * @return  
 */
private Attributes getAttributes(View view) {
    EditText domainField = (EditText) findViewById(R.id.domain);
    EditText iterationsField = (EditText) findViewById(R.id.iterations);
    EditText truncationField = (EditText) findViewById(R.id.truncation);

    String domain = domainField.getText().toString();
    Integer iterations = null;
    try {
        iterations = ((0 == iterationsField.getText().toString().trim().length())
                ? Attributes.DEFAULT_ITERATIONS
                : Integer.parseInt(iterationsField.getText().toString()));
    } catch (ClassCastException e) {
        Log.e(Env.LOG_CATEGORY, "ERROR: Caught " + e);
        e.printStackTrace();
        iterations = Attributes.DEFAULT_ITERATIONS;
    }

    Integer truncation = null;
    try {
        truncation = ((0 == truncationField.getText().toString().trim().length()) ? Attributes.NO_TRUNCATION
                : Integer.parseInt(truncationField.getText().toString()));
    } catch (ClassCastException e) {
        Log.e(Env.LOG_CATEGORY, "ERROR: Caught " + e);
        e.printStackTrace();
        truncation = Attributes.NO_TRUNCATION;
    }

    Attributes attributes = new Attributes(domain, iterations, truncation);

    return attributes;
}

From source file:com.andrewshu.android.reddit.submit.SubmitLinkActivity.java

private boolean validateLinkForm() {
    final EditText titleText = (EditText) findViewById(R.id.submit_link_title);
    final EditText urlText = (EditText) findViewById(R.id.submit_link_url);
    final EditText redditText = (EditText) findViewById(R.id.submit_link_reddit);
    if (StringUtils.isEmpty(titleText.getText())) {
        Common.showErrorToast("Please provide a title.", Toast.LENGTH_LONG, this);
        return false;
    }//from   www.  jav a2 s  . c om
    if (StringUtils.isEmpty(urlText.getText())) {
        Common.showErrorToast("Please provide a URL.", Toast.LENGTH_LONG, this);
        return false;
    }
    if (StringUtils.isEmpty(redditText.getText())) {
        Common.showErrorToast("Please provide a subreddit.", Toast.LENGTH_LONG, this);
        return false;
    }
    return true;
}

From source file:com.example.pyrkesa.shwc.LoginActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_log);/*from  ww  w.  j  av a  2s .co m*/

    final ModelFactory model = (ModelFactory) ModelFactory.getContext();
    UserAuthenticate = model.UserAuthenticate;
    //For settings option-- put it in the first acticity on the onCreate function
    if (getIntent().getBooleanExtra("Exit me", false)) {

        finish();
    }

    if (LoginActivity.UserAuthenticate) {
        Intent homepage = new Intent(getApplicationContext(), MainActivity.class);
        homepage.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(homepage);
        finish();
    }

    final Handler searchipHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            String shwcipadress = msg.getData().getString("ip");
            if (shwcipadress != null) {
                if (LoginActivity.UserAuthenticate == false) {
                    LoginActivity.shwcserverFound = true;
                    LoginActivity.url_all_box = "http://" + shwcipadress
                            + "/SHWCDataManagement/Box/get_all_box.php";
                    LoginActivity.url_authenticate = "http://" + shwcipadress
                            + "/SHWCDataManagement/Users/authenticate.php";
                    LoginActivity.url_authenticateByDevice = "http://" + shwcipadress
                            + "/SHWCDataManagement/Users/authenticateByDevice.php";

                    Log.d("SHWCServer", "IP=" + shwcipadress);

                    String android_id = Secure.getString(getContentResolver(), Secure.ANDROID_ID);

                    Log.d("Android id :", android_id);

                    ArrayList<String> Logs1 = new ArrayList<String>();
                    Logs1.add(url_authenticateByDevice);
                    Logs1.add(android_id);
                    Logs1.add(url_all_box);
                    new AuthenticateUserByDevice().execute(Logs1);
                }
            }

        }
    };

    // Run the ServiceNSD to find the shwcserver
    //final FindServicesNSD zeroconf=new FindServicesNSD((NsdManager)getSystemService(NSD_SERVICE), "_http._tcp",searchipHandler);
    //zeroconf.run();
    // LoginActivity.x=zeroconf;

    // simulation dcouverte serveur shwc
    LoginActivity.shwcserverFound = true;
    model.api_url = "http://" + "10.0.1.5" + "/SHWCDataManagement/";
    LoginActivity.url_all_box = model.api_url + "Box/get_all_box.php";
    LoginActivity.url_authenticate = model.api_url + "Users/authenticate.php";
    LoginActivity.url_authenticateByDevice = model.api_url + "Users/authenticateByDevice.php";

    String android_id = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
    Log.d("Android id :", android_id);

    ArrayList<String> Logs1 = new ArrayList<String>();
    Logs1.add(url_authenticateByDevice);
    Logs1.add(android_id);
    Logs1.add(url_all_box);

    if (getIntent().hasExtra("logout")) {
        new LoadAllBoxes().execute(url_all_box);
    } else {
        new AuthenticateUserByDevice().execute(Logs1);
    }

    /// end simulation

    LogInButton = ((ImageButton) this.findViewById(R.id.LogInButton));
    // Get login and password from EditText
    final EditText login = ((EditText) this.findViewById(R.id.login));
    final EditText password = ((EditText) this.findViewById(R.id.password));
    final Spinner box_choice = ((Spinner) this.findViewById(R.id.box_choice));

    LogInButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            if (LoginActivity.shwcserverFound) {
                String pass = password.getText().toString();
                String log = login.getText().toString();
                String box = box_choice.getSelectedItem().toString();

                String android_id1 = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
                ArrayList<String> Logs = new ArrayList<String>();
                Logs.add(log);
                Logs.add(pass);
                Logs.add(url_authenticate);
                Logs.add(android_id1);
                Logs.add(box);
                new AuthenticateUser().execute(Logs);
            } else {
                Toast.makeText(LoginActivity.this, "Systme SHWC indisponible !", Toast.LENGTH_LONG).show();
            }

        }
    });
    // on seleting single product
    // launching Edit Product Screen

}

From source file:eu.codeplumbers.cosi.activities.NoteDetailsActivity.java

private void getNoteTitle(final SimpleDateFormat isoFormat, final Date date) {
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(NoteDetailsActivity.this);
    alertDialog.setTitle("Title");
    alertDialog.setMessage("Enter note title");

    final EditText input = new EditText(NoteDetailsActivity.this);
    if (note.getTitle() != "") {
        input.setText(note.getTitle());//  w  w w .  j  a v  a 2  s . co m
    }
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT);
    input.setLayoutParams(lp);
    alertDialog.setView(input);

    alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            String title = input.getText().toString();
            note.setTitle(title);

            ArrayList<String> list = new ArrayList<String>();
            list.add(note.getTitle());
            note.setPath(new JSONArray(list).toString());
            note.setLastModificationDate(isoFormat.format(date));
            note.setLastModificationValueOf(String.valueOf(date.getTime()));
            note.setContent(body.getHtml());
            note.save();

            try {
                new SyncDocumentTask(NoteDetailsActivity.this).execute(note.toJsonObject());
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });

    alertDialog.show();

}

From source file:com.zapto.park.ParkActivity.java

public boolean onOptionsItemSelected(MenuItem item) {
    Intent i = null;//from w  w  w. j a va 2 s  . com
    switch (item.getItemId()) {
    // Add User
    case 1:
        Dialog d = new Dialog(cActivity);
        final Dialog dialog = d;
        d.setContentView(R.layout.dialog_add_employee);
        d.setTitle(R.string.create_user_title);

        final EditText first_name = (EditText) d.findViewById(R.id.employee_first);
        final EditText last_name = (EditText) d.findViewById(R.id.employee_last);
        Button button_getinfo = (Button) d.findViewById(R.id.button_getinfo);

        button_getinfo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EmployeeDB edb = new EmployeeDB(context);

                String first = first_name.getText().toString();
                String last = last_name.getText().toString();

                ContentValues cv = new ContentValues();
                cv.put("totable_first", first);
                cv.put("totable_last", last);
                cv.put("totable_license", Globals.LICENSE_KEY);

                // Log request in database.
                ContentValues cv2 = new ContentValues();
                cv2.put("first", first);
                cv2.put("last", last);

                // Query database.
                edb.insertEmployee(cv2);

                // Close our database.
                edb.close();

                dialog.dismiss();
            }
        });

        d.show();

        break;
    // Settings
    case 2:
        Log.i(LOG_TAG, "Settings menu clicked.");
        i = new Intent(this, SettingsActivity.class);
        startActivity(i);
        break;
    case 3:
        Log.i(LOG_TAG, "View Log Loading.");
        i = new Intent(this, ListViewActivity.class);
        startActivity(i);
        break;
    case 4:
        doInit();
        Handler handler = new Handler();
        handler.post(new Runnable() {
            @Override
            public void run() {
                updateEmployees();
                doPendingRequests();
            }
        });
        break;
    case 5:
        Log.i(LOG_TAG, "SendEmailActivity Loading.");
        i = new Intent(this, SendEmailActivity.class);
        startActivity(i);
        break;
    case 6:
        Log.i(LOG_TAG, "View Log Loading.");
        i = new Intent(this, ListViewActivity.class);
        startActivity(i);
        break;
    }

    return true;
}

From source file:com.andrewshu.android.reddit.submit.SubmitLinkActivity.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    CookieSyncManager.createInstance(getApplicationContext());

    mSettings.loadRedditPreferences(this, mClient);
    setRequestedOrientation(mSettings.getRotation());
    setTheme(mSettings.getTheme());//from   w  ww. j  a v  a 2  s .  co  m

    setContentView(R.layout.submit_link_main);

    final FrameLayout fl = (FrameLayout) findViewById(android.R.id.tabcontent);
    if (Util.isLightTheme(mSettings.getTheme())) {
        fl.setBackgroundResource(R.color.gray_75);
    } else {
        fl.setBackgroundResource(R.color.black);
    }

    mTabHost = getTabHost();
    mTabHost.addTab(
            mTabHost.newTabSpec(Constants.TAB_LINK).setIndicator("link").setContent(R.id.submit_link_view));
    mTabHost.addTab(
            mTabHost.newTabSpec(Constants.TAB_TEXT).setIndicator("text").setContent(R.id.submit_text_view));
    mTabHost.setOnTabChangedListener(new OnTabChangeListener() {
        public void onTabChanged(String tabId) {
            // Copy everything (except url and text) from old tab to new tab
            final EditText submitLinkTitle = (EditText) findViewById(R.id.submit_link_title);
            final EditText submitLinkReddit = (EditText) findViewById(R.id.submit_link_reddit);
            final EditText submitTextTitle = (EditText) findViewById(R.id.submit_text_title);
            final EditText submitTextReddit = (EditText) findViewById(R.id.submit_text_reddit);
            if (Constants.TAB_LINK.equals(tabId)) {
                submitLinkTitle.setText(submitTextTitle.getText());
                submitLinkReddit.setText(submitTextReddit.getText());
            } else {
                submitTextTitle.setText(submitLinkTitle.getText());
                submitTextReddit.setText(submitLinkReddit.getText());
            }
        }
    });
    mTabHost.setCurrentTab(0);

    if (mSettings.isLoggedIn()) {
        start();
    } else {
        showDialog(Constants.DIALOG_LOGIN);
    }
}

From source file:fi.mikuz.boarder.gui.internet.Settings.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.internet_settings);
    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);

    @SuppressWarnings("unchecked")
    HashMap<String, String> lastSession = (HashMap<String, String>) getIntent()
            .getSerializableExtra(InternetMenu.LOGIN_KEY);

    try {/*from  www  . j  a v  a 2  s.c  om*/
        mUserId = lastSession.get(InternetMenu.USER_ID_KEY);
        mSessionToken = lastSession.get(InternetMenu.SESSION_TOKEN_KEY);
    } catch (NullPointerException e) {
        Toast.makeText(Settings.this, "Please login", Toast.LENGTH_LONG).show();
        Settings.this.finish();
    }

    Button changePassword = (Button) findViewById(R.id.change_password);

    changePassword.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            LayoutInflater inflater = (LayoutInflater) Settings.this.getSystemService(LAYOUT_INFLATER_SERVICE);
            View layout = inflater.inflate(R.layout.internet_settings_alert_change_password,
                    (ViewGroup) findViewById(R.id.alert_settings_root));

            final EditText oldPasswordInput = (EditText) layout.findViewById(R.id.oldPasswordInput);
            final EditText newPassword1Input = (EditText) layout.findViewById(R.id.newPassword1Input);
            final EditText newPassword2Input = (EditText) layout.findViewById(R.id.newPassword2Input);
            Button submitButton = (Button) layout.findViewById(R.id.submitButton);

            AlertDialog.Builder builder = new AlertDialog.Builder(Settings.this);
            builder.setView(layout);
            builder.setTitle("Change password");

            submitButton.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    String oldPasswordText = oldPasswordInput.getText().toString();
                    String newPassword1Text = newPassword1Input.getText().toString();
                    String newPassword2Text = newPassword2Input.getText().toString();

                    if (!newPassword1Text.equals(newPassword2Text)) {
                        Toast.makeText(Settings.this, "New passwords don't match", Toast.LENGTH_LONG).show();
                    } else if (newPassword1Text.length() < 6) {
                        Toast.makeText(Settings.this, "Password length must be at least 6 characters",
                                Toast.LENGTH_LONG).show();
                    } else {
                        try {
                            mWaitDialog = new TimeoutProgressDialog(Settings.this, "Waiting for response", TAG,
                                    false);
                            HashMap<String, String> sendList = new HashMap<String, String>();
                            sendList.put(InternetMenu.PASSWORD_KEY, Security.passwordHash(newPassword1Text));
                            sendList.put(InternetMenu.OLD_PASSWORD_KEY, Security.passwordHash(oldPasswordText));
                            sendList.put(InternetMenu.USER_ID_KEY, mUserId);
                            sendList.put(InternetMenu.SESSION_TOKEN_KEY, mSessionToken);
                            new ConnectionManager(Settings.this, InternetMenu.mChangePasswordURL, sendList);
                        } catch (NoSuchAlgorithmException e) {
                            mWaitDialog.dismiss();
                            String msg = "Couldn't make md5 hash";
                            Toast.makeText(Settings.this, msg, Toast.LENGTH_LONG).show();
                            Log.e(TAG, msg, e);
                        }
                    }
                }
            });

            builder.show();
        }
    });

    Button changeEmail = (Button) findViewById(R.id.change_email);

    changeEmail.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            LayoutInflater inflater = (LayoutInflater) Settings.this.getSystemService(LAYOUT_INFLATER_SERVICE);
            View layout = inflater.inflate(R.layout.internet_settings_alert_change_email,
                    (ViewGroup) findViewById(R.id.alert_settings_root));

            final EditText passwordInput = (EditText) layout.findViewById(R.id.passwordInput);
            final EditText newEmailInput = (EditText) layout.findViewById(R.id.newEmailInput);
            Button submitButton = (Button) layout.findViewById(R.id.submitButton);

            AlertDialog.Builder builder = new AlertDialog.Builder(Settings.this);
            builder.setView(layout);
            builder.setTitle("Change email");

            submitButton.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    String passwordText = passwordInput.getText().toString();
                    String newEmailText = newEmailInput.getText().toString();

                    try {
                        mWaitDialog = new TimeoutProgressDialog(Settings.this, "Waiting for response", TAG,
                                false);
                        HashMap<String, String> sendList = new HashMap<String, String>();
                        sendList.put(InternetMenu.PASSWORD_KEY, Security.passwordHash(passwordText));
                        sendList.put(InternetMenu.EMAIL_KEY, newEmailText);
                        sendList.put(InternetMenu.USER_ID_KEY, mUserId);
                        sendList.put(InternetMenu.SESSION_TOKEN_KEY, mSessionToken);
                        new ConnectionManager(Settings.this, InternetMenu.mChangeEmailURL, sendList);
                    } catch (NoSuchAlgorithmException e) {
                        mWaitDialog.dismiss();
                        String msg = "Couldn't make md5 hash";
                        Toast.makeText(Settings.this, msg, Toast.LENGTH_LONG).show();
                        Log.e(TAG, msg, e);
                    }
                }
            });

            builder.show();
        }
    });

}