25

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? :?:

0

3 Answers 3

6

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

4

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

Check this link.

4
  • Thank you, Macarse. I know this android:password. But I just want to use AlertDialog as Login form. Is it good to use like that? My application has main tab layout and then related activity will appear. It looks like built-in contacts. I'd like to appear this login layout whenever user starts to use my application. I just know onResume() event but if i use this event, sometimes login layout will appear twice or more. So how to code to appear each time user starts to use application.
    – soclose
    Jun 10, 2010 at 4:34
  • It worked. I use LayoutInflater, based on this link - coderanch.com/t/434894/Android/Mobile/values
    – soclose
    Jun 10, 2010 at 7:29
  • I can't get my pin code value although it shows into asterisk. I posted my updated code in my post. Please check my missing or wrong point.
    – soclose
    Jun 15, 2010 at 3:52
  • Yap! I get it! my fault is in xml. I missed to type "android" in "id" declaration part. :P =D
    – soclose
    Jun 15, 2010 at 7:46
-1

Replace:

EditText rate = (EditText)findViewById((R.id.rate));

With:

EditText rate = (EditText)wind.findViewById((R.id.rate));
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.