2014-11-19 5 views
18

मैं एक Android ऐप्लिकेशन के लिए लॉगिन स्क्रीन पाने के लिए कोशिश कर रहा हूँ और अब तक यह मेरा कोड है:एंड्रॉयड imeOptions = "actionDone" काम नहीं कर

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 


    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:orientation="vertical"> 

     <EditText 
      android:id="@+id/username" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:hint="Username" 
      android:inputType="text" 
      android:singleLine="true" 
      android:imeOptions="actionNext"> 

      <requestFocus /> 
     </EditText> 

     <EditText 
      android:id="@+id/password" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:hint="Password" 
      android:inputType="textPassword" 
      android:singleLine="true" 
      android:imeOptions="actionDone" /> 

     <Button 
      android:id="@+id/buttonLaunchTriage" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:text="@string/login" /> 
    </LinearLayout> 



</RelativeLayout> 

जब मैं इसे चलाने के लिए प्रयास करते हैं, कुंजीपटल सही से पता चलता चाबियाँ लेकिन जब मैं पासवर्ड दर्ज करने के बाद दबाए जाने की कोशिश करता हूं, कुछ भी नहीं होता है। मैं बटन प्रेस को संभालने के लिए इस का उपयोग कर रहा:

private void setupLoginButton() { 
    Button launchButton = (Button) findViewById(R.id.buttonLaunchTriage); 
    launchButton.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      EditText username = (EditText) findViewById(R.id.patient_start_userName_value); 
      EditText password = (EditText) findViewById(R.id.patient_start_password_value); 

      try { 
       if(TriageApplicationMain.validateUser(username.getText().toString(),password.getText().toString(),getApplicationContext())) 
       { 
       Toast.makeText(StartActivity.this, 
         "Launching Triage Application", Toast.LENGTH_SHORT) 
         .show(); 
       startActivity(new Intent(StartActivity.this, MainActivity.class)); 
       } 

       else 
        { 
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
          StartActivity.this); 


         // set dialog message 
         alertDialogBuilder 
          .setMessage("Incorrect Credentials") 
          .setCancelable(false) 
          .setPositiveButton("OK",new DialogInterface.OnClickListener() { 
           public void onClick(DialogInterface dialog,int id) { 
            // if this button is clicked, close 
            // current activity 
           dialog.cancel();  
           } 
           }); 


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

          // show it 
          alertDialog.show(); 

        } 
       } 


      catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
     } 
    }); 

} 

मैं जानता हूँ कि इस कोड का एक बहुत कुछ है, लेकिन यह बहुत अच्छा होगा अगर कोई मुझे यहाँ मदद कर सकता है। यह एक स्कूल परियोजना के लिए है।

पीएस: मैंने इसे पोस्ट करने से पहले ठोस घंटे के लिए Google के माध्यम से खोज की है, इसलिए कृपया ऐसा करने के लिए आलोचना न करें। यदि आपको एक लिंक मिलता है जो उपयोगी है तो कृपया साझा करें।

+0

वास्तव में क्या आप "किया" से उम्मीद कर रहे हैं मुलायम इनपुट कीबोर्ड में? कीबोर्ड को छुपाएं या लॉगिन की ओर बढ़ें? – waqaslam

+0

मैं एक ही मुद्दे का सामना करना पड़ गया है, जिसे आप जोड़ना होगा: एंड्रॉयड: imeActionLabel = "हो गया" एंड्रॉयड: singleLine = "true" यहाँ जवाब है http://stackoverflow.com/questions/5578991/actiondone -इमोप्शन-इन-वर्क-ऑन-एडिटेक्स्ट-इन-एंड्रॉइड-2-3/5579 9 44 # 5579 9 44 –

उत्तर

29

जब आप कीबोर्ड में "पूर्ण" क्लिक करते हैं तो उस क्रिया को लागू करने के लिए आपको संपादन टेक्स्ट के लिए OnEditorActionListener सेट करना चाहिए, जिसे आप करना चाहते हैं।

इस प्रकार, आप जैसे कुछ कोड लिखने की जरूरत है:

password.setOnEditorActionListener(new OnEditorActionListener() { 
    @Override 
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
     if (actionId == EditorInfo.IME_ACTION_DONE) { 
      // Do whatever you want here 
      return true; 
     } 
     return false; 
    } 
}); 

android developer site

+0

उत्तर के लिए धन्यवाद। मैं थोड़ी देर के लिए stackoverflow से थोड़ी दूर गिरा दिया।वापस अब :) – Mak

19

Qianqian सही है पर ट्यूटोरियल देखें। आपका कोड केवल बटन क्लिक ईवेंट के लिए सुनता है, संपादक एक्शन ईवेंट के लिए नहीं।

मैं यह जोड़ना चाहता हूं कि कुछ फोन विक्रेता सही तरीके से कार्यवाही लागू नहीं कर सकते हैं। मैं उदाहरण के लिए एक Lenovo A889 के साथ इस परीक्षण किया है, और कहा कि फोन कभी नहीं EditorInfo.IME_ACTION_DONE भेजता है जब आप पूर्ण दबाएँ, यह हमेशा के लिए भेजता है EditorInfo.IME_ACTION_UNSPECIFIED तो मैं वास्तव में की तरह

myEditText.setOnEditorActionListener(new EditText.OnEditorActionListener() { 
    @Override 
    public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) 
    { 
    boolean handled=false; 

    // Some phones disregard the IME setting option in the xml, instead 
    // they send IME_ACTION_UNSPECIFIED so we need to catch that 
    if(EditorInfo.IME_ACTION_DONE==actionId || EditorInfo.IME_ACTION_UNSPECIFIED==actionId) 
    { 
     // do things here 

     handled=true; 
    } 

    return handled; 
    } 
}); 

यह भी ध्यान रखें "संभाला" झंडा कुछ के साथ अंत (Qianqian उस भाग को समझाया नहीं है)। ऐसा हो सकता है कि अन्य ऑनडिटर एक्शन लिस्टेनर्स ऊपर एक अलग प्रकार की घटनाओं के लिए सुन रहे हैं। यदि आपकी विधि गलत लौटती है, तो इसका मतलब है कि आपने इस घटना को संभाल नहीं लिया है और यह दूसरों को दिया जाएगा। यदि आप सच लौटते हैं तो इसका मतलब है कि आपने इसे संभाला/खाया और यह दूसरों को नहीं भेजा जाएगा।

+2

धन्यवाद, मुझे उम्मीद है कि IME_ACTION_SENDECIED अपेक्षित IME_ACTION_SEND – flaviodesousa

+1

की बजाय यह सही उत्तर – HendraWD

24

बस अपने संपादन टेक्स्ट में android:inputType="..." जोड़ें। यह काम करेगा!! :)

4

उपयोग android:inputType="Yours" तो

android:lines="1" 
android:imeOptions="actionDone" 
0

आप OnEditorActionListener EditText के लिए कार्रवाई आप जब उपयोगकर्ता कुंजीपटल में क्लिक करता है "हो गया" प्रदर्शन करने के लिए चाहते हैं लागू करने के लिए स्थापित करना चाहिए।

0

बहुत सी बातें की कोशिश के बाद, यह क्या मेरे लिए काम किया है:

android:maxLines="1" 
    android:inputType="text" 
    android:imeOptions="actionDone" 
+0

होना चाहिए यह प्रश्न का उत्तर प्रदान नहीं करता है। एक बार आपके पास पर्याप्त [प्रतिष्ठा] (https://stackoverflow.com/help/whats-reputation) हो जाने पर आप [किसी भी पोस्ट पर टिप्पणी कर सकेंगे] (https://stackoverflow.com/help/privileges/comment); इसके बजाय, [उन उत्तरों को प्रदान करें जिन्हें पूछताछ से स्पष्टीकरण की आवश्यकता नहीं है] (https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can- i-कर-बजाय)। - [समीक्षा से] (/ समीक्षा/कम गुणवत्ता वाले पदों/18007334) –

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