2012-10-02 4 views
11

पर पासवर्ड प्रॉम्प्ट, जब मैं गलत पासवर्ड दर्ज करता हूं, तो मैं पासवर्ड प्रॉम्प्ट करने की कोशिश कर रहा हूं, यह "रद्द" या "पुनः प्रयास" करने के लिए एक संवाद दिखाएगा और जब उपयोगकर्ता "पुनः प्रयास" पर क्लिक करेगा, तो यह प्रदर्शित होगा पासवर्ड फिर से संकेत।एंड्रॉइड

नीचे छवियों को वर्णन करने मैं क्या मतलब

enter image description here

enter image description here

यह मैं इसे कैसे किया है कर रहे हैं

/** RETRIEVE VIEW FROM DIALOGPROMPT.XML AND SET VIEW AS AN ALERTDIALOG BUILDER **/ 
       LayoutInflater li = LayoutInflater.from(context); 
       View promptsView = li.inflate(R.layout.searchprompt, null); 
       AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); 
       alertDialogBuilder.setView(promptsView); 

       final EditText userInput = (EditText) promptsView 
         .findViewById(R.id.user_input); 


       // set dialog message 
       alertDialogBuilder 
        .setCancelable(false) 
        .setNegativeButton("Go", 
         new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog,int id) { 
          /** DO THE METHOD HERE WHEN PROCEED IS CLICKED*/ 
          String user_text = (userInput.getText()).toString(); 

          /** CHECK FOR USER'S INPUT **/ 
          if (user_text.equals("oeg")) 
          { 
           Log.d(user_text, "HELLO THIS IS THE MESSAGE CAUGHT :)"); 
           Search_Tips(user_text); 

          } 
          else{ 
           Log.d(user_text,"string is empty"); 
           String message = "The password you have entered is incorrect." + " \n" + "Please try again"; 
           AlertDialog.Builder builder = new AlertDialog.Builder(context); 
           builder.setTitle("Error"); 
           builder.setMessage(message); 
           builder.setPositiveButton("Cancel", null); 
           builder.setNegativeButton("Retry", null); 
           builder.create().show(); 

          } 
          } 
         }) 
        .setPositiveButton("Cancel", 
         new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog,int id) { 
         dialog.cancel(); 
         } 
         }); 

       // create alert dialog 
       AlertDialog alertDialog = alertDialogBuilder.create(); 

       // show it 
       alertDialog.show(); 

      } 
     }); 

किसी को भी यह कैसे करना है पता है?

उत्तर

10

मैंने अपनी समस्या हल कर ली है। मैंने अपने अलर्ट संवाद के लिए एक विधि बनाई और फिर जब मैं "पुनः प्रयास" पर क्लिक करता हूं, तो मैं विधि को फिर से कॉल करूंगा। :)

public void showDialog() 
{ 

    LayoutInflater li = LayoutInflater.from(context); 
    View promptsView = li.inflate(R.layout.searchprompt, null); 
    final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); 
    alertDialogBuilder.setView(promptsView); 

    final EditText userInput = (EditText) promptsView 
      .findViewById(R.id.user_input); 


    // set dialog message 
    alertDialogBuilder 
     .setCancelable(false) 
     .setNegativeButton("Go", 
      new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog,int id) { 
       /** DO THE METHOD HERE WHEN PROCEED IS CLICKED*/ 
       String user_text = (userInput.getText()).toString(); 

       /** CHECK FOR USER'S INPUT **/ 
       if (user_text.equals("oeg")) 
       { 
        Log.d(user_text, "HELLO THIS IS THE MESSAGE CAUGHT :)"); 
        Search_Tips(user_text); 

       } 
       else{ 
        Log.d(user_text,"string is empty"); 
        String message = "The password you have entered is incorrect." + " \n \n" + "Please try again!"; 
        AlertDialog.Builder builder = new AlertDialog.Builder(context); 
        builder.setTitle("Error"); 
        builder.setMessage(message); 
        builder.setPositiveButton("Cancel", null); 
        builder.setNegativeButton("Retry", new DialogInterface.OnClickListener() { 
         @Override 
         public void onClick(DialogInterface dialog, int id) { 
          showDialog(); 
         } 
        }); 
        builder.create().show(); 

       } 
       } 
      }) 
     .setPositiveButton("Cancel", 
      new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog,int id) { 
      dialog.dismiss(); 
      } 

      } 

     ); 

    // create alert dialog 
    AlertDialog alertDialog = alertDialogBuilder.create(); 

    // show it 
    alertDialog.show(); 

} 
+4

यह समाधान याद आ रही है 'R.layout.searchprompt',' R.id.user_input' और 'Search_Tips()'। –

3

यहां एक अच्छा नमूना है - http://www.mkyong.com/android/android-prompt-user-input-dialog-example मैकॉन्ग से।

पासवर्ड के लिए

लेआउट फ़ाइल का संकेत

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/layout_root" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:padding="10dp" > 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Type Your Message : " 
     android:labelFor="@+id/editTextDialogUserInput" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

    <EditText 
     android:id="@+id/editTextDialogUserInput" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:inputType="textPassword" > 

     <requestFocus /> 

    </EditText> 

</LinearLayout>