2011-11-11 177 views
0

好吧,所以我有一個警報對話框,顯示一個Edittext請求活動中的密碼。一切工作正常我也嘗試使用一個簡單的佈局文件。現在的問題是,每當我嘗試強制執行數字輸入時,它都會顯示數字輸入,但拒絕顯示正在輸入的任何數字輸入,同時在日誌中顯示空白字符串。它可以正常工作。但也有一個奇怪的問題,如果你輸入的第一個字符是數字,那麼它仍然有同樣的問題,但如果你輸入一些非整數字符,然後數字,那麼它是好的例如。 a5是好的,但如果你輸入5,然後山姆問題,當你特別強制執行android:inputType =「number」 現在,當我在常規活動(作爲一個完整性檢查)嘗試這個工作正常不只是在alertDialogAndroid提醒對話框數字輸入

這裏是相關代碼

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/password_view" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_marginLeft="20dip" 
     android:layout_marginRight="20dip" 
     android:text="Password" 
     android:gravity="left" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 

    <EditText 
     android:id="@+id/password" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:layout_marginLeft="20dip" 
     android:layout_marginRight="20dip" 
     android:scrollHorizontally="true" 
     android:autoText="false" 
     android:capitalize="none" 
     android:gravity="fill_horizontal" 
     android:password="true" 
     android:textAppearance="?android:attr/textAppearanceMedium"/> 

</LinearLayout> 



    public void passwordChecker() { 
     // TODO Auto-generated method stub 
     //final EditText input = new EditText(PrivacyActivity.this); 
     //input.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); 
     //input.setInputType(InputType.TYPE_CLASS_NUMBER); 
     //input.setInputType(InputType.TY); 
     //input.setTransformationMethod(PasswordTransformationMethod.getInstance()); 
     LayoutInflater factory = LayoutInflater.from(mContext); 
     final View view = factory.inflate(R.layout.password, null); 

     final EditText mPassword=(EditText) view.findViewById(R.id.password); 

     //final EditText test=(EditText) findViewById(R.id.password); 

     final EditText input = new EditText(mContext); 

     if(true){ 
      new AlertDialog.Builder(PrivacyActivity.this).setMessage("Enter the password") 
      .setCancelable(false) 
      .setPositiveButton("Ok", new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface dialog, int id) { 
        //perform deletion from database 
        dialog.cancel(); 

        Log.e("error", "Apple "+ mPassword.getText().toString()); 


       } 
      }).setView(input) 
      .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface dialog, int id) { 
        .... 
       } 
      }).create().show(); 
     } 
    } 
+1

android:inputType =「number」在你的edittext xml中試試這個,讓我知道發生了什麼。 – user370305

+0

嘿,我說我有那個BU輸入不顯示(數字鍵盤顯示)也沒有,因爲當我做gettext沒有什麼在那裏 – neelabh

回答

0

嘗試......

<EditText 
     android:id="@+id/password" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:layout_marginLeft="20dip" 
     android:layout_marginRight="20dip" 
     android:singleLine="true" 
     android:autoText="false" 
     android:capitalize="none" 
     android:gravity="fill_horizontal" 
     android:password="true"   
     android:textAppearance="?android:attr/textAppearanceMedium"/> 
+0

是啊我讀了關於android:singleLine =「true」在一些論壇嘗試了它,但這也沒有幫助 – neelabh

0

所以我不好我花了年齡後,我發現這個問題 問題是不是其中任何上述迴應。出於某種原因,我未能添加上面不存在的代碼。

所以我用我的一個函數 覆蓋了警告對話框,如下所示。因爲我只是聽KEYCODE_DPAD_UPKEYCODE_DPAD_CENTER 它搞亂了數字鍵盤輸入

.setNegativeButton("I don't Agree", new DialogInterface.OnClickListener() { 
        @Override 
        public void onClick(DialogInterface dialog, int id) { 
         finish(); 
        } 
       }).setOnKeyListener(new DialogInterface.OnKeyListener() { 
        @Override 
        public boolean onKey(DialogInterface dialog, int keyCode, 
          KeyEvent event) { 
         if (keyCode < KeyEvent.KEYCODE_DPAD_UP || keyCode > KeyEvent.KEYCODE_DPAD_CENTER) { 
          return true; 
         } 
         return false; 
        } 
       }).create().show(); 

這樣的人,如果有幫助檢查ü[R聽什麼鍵以及。