質問

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

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

どのようにすべての入力テキストが「***」のように表示されることをコードに - アスタリスク

それはアスタリスクに示しているが、私は私のピンコード値を取得することはできません。私のコードは以下の通りです。

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

私は値を入力しますが、GETナル!

どのように解決するには?

のデバッグは、このステートメントで停止しています。私はmUserTextヌル値を上回る指摘すると、ポップアップで表示されてます。

  

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

私は、Android 1.6を使用しています。それはバージョンに依存していますか? :?:

役に立ちましたか?

解決

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

チェックこののリンクます。

他のヒント

この問題は、非推奨android:passwordを使用せずに解決することができます。私の答えはここにのhref="https://stackoverflow.com/questions/2420181/android-numeric-password-field/4014588#4014588">

に置き換えます:

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

EditText rate = (EditText)wind.findViewById((R.id.rate));
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top