25

AlertDialog をログイン、PIN コード、またはパスワード ダイアログとして使用したいと考えています。ここに私のコードがあります -

    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();

すべての入力テキストが「 *** 」のように表示されるようにコーディングする方法 - アスタリスク

アスタリスクで表示されますが、PIN コードの値を取得できません。私のコードは以下です

    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" /> 

値を入力したのにnullになってしまう!

の解き方?

デバッグはこのステートメントで停止します。ポップアップに表示されている mUserText null 値の上を指したとき。

文字列 strPinCode = mUserText.getText().toString();

Android1.6を使用しています。バージョンに依存しますか?:?:

4

3 に答える 3

6

この問題は deprecated を使用しなくても解決できますandroid:passwordここで私の答えを見てください。

于 2010-10-25T12:41:52.547 に答える
4

あなたEditTextが持っている必要がありandroid:password="true"ます。

このリンクを確認してください。

于 2010-06-10T03:04:53.767 に答える
-1

交換:

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

と:

EditText rate = (EditText)wind.findViewById((R.id.rate));
于 2011-01-20T09:54:59.367 に答える