Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AlertDialog Input Text

Tags:

I'd like to use AlertDialog as a Login or pin code or password dialog. Here is my code -

    AlertDialog.Builder alert = new AlertDialog.Builder(this);                  alert.setTitle("Login");   alert.setMessage("Enter Pin :");                   // Set an EditText view to get user input     final EditText input = new EditText(this);   alert.setView(input);      alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {       public void onClick(DialogInterface dialog, int whichButton) {           String value = input.getText().toString();         Log.d( TAG, "Pin Value : " + value);         return;                          }        });        alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {          public void onClick(DialogInterface dialog, int which) {             // TODO Auto-generated method stub             return;            }     });             alert.show(); 

How to code that all input text will appear like ' *** ' - asterisk

I can't get my pin code value although it shows into asterisk. my code is below

    private void accessPinCode_2() {     LayoutInflater factory = LayoutInflater.from(this);     final View textEntryView = factory.inflate(R.layout.dialog_login, null);     AlertDialog.Builder alert = new AlertDialog.Builder(this);                      alert.setTitle("Login");    alert.setMessage("Enter Pin :");                  alert.setView(textEntryView);      alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {       public void onClick(DialogInterface dialog, int whichButton) {           //String value = input.getText().toString();         EditText mUserText;         mUserText = (EditText) textEntryView.findViewById(R.id.txt_password);         String strPinCode = mUserText.getText().toString();         Log.d( TAG, "Pin Value : " + strPinCode);         return;                          }        });        alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {          public void onClick(DialogInterface dialog, int which) {             // TODO Auto-generated method stub             return;            }     });             alert.show();   }} 

dialog_login.xml

<?xml version="1.0" encoding="utf-8"?> <EditText xmlns:android="http://schemas.android.com/apk/res/android"          android:id="@+id/txt_password"          android:password="true"          android:layout_height="wrap_content"          android:layout_width="250px"          android:layout_centerHorizontal="true"          android:layout_below="@+id/password_text"          android:singleLine="true" />  

I entered the value, but get null!

how to solve?

Debugging is stopped at this statement. When I pointed above mUserText null value being shown in popup.

String strPinCode = mUserText.getText().toString();

I use Android 1.6. Does it depend on Version? :?:

like image 541
soclose Avatar asked Jun 10 '10 02:06

soclose


People also ask

Is AlertDialog deprecated?

A simple dialog containing an DatePicker . This class was deprecated in API level 26.

What is AlertDialog message?

AlertDialog. A dialog that can show a title, up to three buttons, a list of selectable items, or a custom layout. DatePickerDialog or TimePickerDialog. A dialog with a pre-defined UI that allows the user to select a date or time.

How do I change the font in AlertDialog?

If you only want to change text format, you can just override alertDialogTheme attribute to change the theme for the AlertDialog . <style name="MyTheme" parent="Theme. AppCompat.


2 Answers

This problem can be solved without using deprecated android:password. See my answer here.

like image 174
Viktor Brešan Avatar answered Sep 24 '22 21:09

Viktor Brešan


You EditText should have android:password="true".

Check this link.

like image 22
Macarse Avatar answered Sep 23 '22 21:09

Macarse