2010-06-10 9 views
23

मैं लॉगिन या पिन कोड या पासवर्ड संवाद के रूप में 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" /> 

मैं मान डाला, लेकिन अशक्त मिलता है!

कैसे हल करें?

इस कथन पर डिबगिंग रोक दी गई है। जब मैंने पॉपअप में दिखाए गए mUserText शून्य मान से ऊपर की ओर इशारा किया।

स्ट्रिंग strPinCode = mUserText.getText()। ToString();

मैं एंड्रॉइड 1.6 का उपयोग करता हूं। क्या यह संस्करण पर निर्भर करता है? :?:

उत्तर

4

आप EditTextandroid:password="true" होना चाहिए।

this लिंक देखें।

+0

धन्यवाद, Macarse। मुझे यह एंड्रॉइड पता है: पासवर्ड। लेकिन मैं सिर्फ अलर्टडिअलॉग को लॉगिन फॉर्म के रूप में उपयोग करना चाहता हूं। क्या इसका उपयोग करना अच्छा है? मेरे एप्लिकेशन में मुख्य टैब लेआउट है और फिर संबंधित गतिविधि दिखाई देगी। यह अंतर्निहित संपर्कों की तरह दिखता है। जब भी उपयोगकर्ता मेरे आवेदन का उपयोग करना शुरू करता है तो मैं यह लॉगिन लेआउट दिखाना चाहता हूं। मैं बस रेस्यूम() घटना पर जानता हूं लेकिन अगर मैं इस घटना का उपयोग करता हूं, तो कभी-कभी लॉगिन लेआउट दो या दो से अधिक दिखाई देगा। तो जब भी उपयोगकर्ता एप्लिकेशन का उपयोग शुरू करता है तो प्रत्येक बार प्रदर्शित होने के लिए कोड कैसे करें। – soclose

+0

यह काम किया। मैं इस लिंक के आधार पर लेआउटइनफ्लेटर का उपयोग करता हूं - http://www.coderanch.com/t/434894/Android/Mobile/values ​​ – soclose

+0

मुझे अपना पिन कोड वैल्यू नहीं मिल सकता है हालांकि यह तारांकन में दिखाया गया है। मैंने अपने पोस्ट में अपना अपडेट किया गया कोड पोस्ट किया। कृपया मेरा लापता या गलत बिंदु देखें। – soclose

6

यह समस्या बहिष्कृत android:password का उपयोग किये बिना हल की जा सकती है। मेरा उत्तर here देखें।

-1

बदलें:

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

के साथ:

EditText rate = (EditText)wind.findViewById((R.id.rate)); 
+2

क्या, ....../??????? / –

संबंधित मुद्दे