2011-10-23 14 views
7

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

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent" android:background="@drawable/sfondo"> 
<LinearLayout android:id="@+id/linearLayout1" 
    android:layout_width="match_parent" android:layout_height="wrap_content"> 
    <ImageButton android:id="@+id/backPersonalizza" 
     android:src="@drawable/back" android:background="@null" 
     android:layout_marginTop="10dip" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:layout_marginLeft="5dp"></ImageButton> 
    <TextView android:layout_height="wrap_content" 
     android:gravity="center" 
     android:textColor="@android:color/black" android:id="@+id/testoSuggerimenti" 
     android:text="Personalizza il testo e le icone. Clicca su una delle icone e scegli l'immagine preferita" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:layout_width="wrap_content" 
     android:layout_marginTop="10dp" 
     android:layout_marginRight="5dp" 
     ></TextView> 
</LinearLayout> 
<LinearLayout android:id="@+id/linearLayout2" 
    android:layout_height="wrap_content" android:layout_width="match_parent" 
    android:orientation="vertical" android:layout_marginTop="20dp"> 
    <LinearLayout android:id="@+id/linearLayout3" 
     android:layout_height="wrap_content" android:layout_width="match_parent"> 
     <EditText android:layout_height="40dp" android:id="@+id/editT1" 
      android:layout_width="115dp" android:layout_marginLeft="32dp" 
      android:layout_marginRight="25dp" android:gravity="center" 
      android:ellipsize="end" android:singleLine="true"> 
      <requestFocus></requestFocus> 
     </EditText> 
     <EditText android:layout_height="40dp" android:id="@+id/editT2" 
      android:layout_width="115dp" android:layout_marginRight="10dp" 
      android:gravity="center" android:ellipsize="end" 
      android:layout_marginLeft="10dp" android:singleLine="true"></EditText> 
    </LinearLayout> 
    <LinearLayout android:layout_weight="1" android:id="@+id/linearLayout4" 
     android:layout_height="match_parent" android:layout_width="wrap_content"> 
     <ImageButton android:layout_height="wrap_content" 
      android:layout_width="wrap_content" android:src="@drawable/tasto1" 
      android:id="@+id/tastoMod1" android:background="@null" 
      android:layout_marginLeft="30dp" android:layout_marginTop="-5dp"></ImageButton> 
     <ImageButton android:layout_height="wrap_content" 
      android:layout_width="wrap_content" android:src="@drawable/tasto2" 
      android:id="@+id/tastoMod2" android:background="@null" 
      android:layout_marginLeft="30dp" android:layout_marginTop="-5dp"></ImageButton> 
    </LinearLayout> 
</LinearLayout> 
<LinearLayout android:id="@+id/linearLayout5" 
    android:layout_height="wrap_content" android:layout_width="match_parent" 
    android:orientation="vertical"> 
    <LinearLayout android:id="@+id/linearLayout6" 
     android:layout_height="wrap_content" android:layout_width="match_parent"> 
     <EditText android:layout_height="40dp" android:id="@+id/editT3" 
      android:layout_width="115dp" android:layout_marginLeft="32dp" 
      android:layout_marginRight="25dp" android:gravity="center" 
      android:ellipsize="end" android:singleLine="true"></EditText> 
     <EditText android:layout_height="40dp" android:id="@+id/editT4" 
      android:layout_width="115dp" android:layout_marginRight="30dp" 
      android:gravity="center" android:ellipsize="end" android:singleLine="true" 
      android:layout_marginLeft="10dp"></EditText> 
    </LinearLayout> 
    <LinearLayout android:id="@+id/linearLayout7" 
     android:layout_height="wrap_content" android:layout_width="match_parent"> 
     <ImageButton android:layout_height="wrap_content" 
      android:layout_width="wrap_content" android:src="@drawable/tasto3" 
      android:id="@+id/tastoMod3" android:background="@null" 
      android:layout_marginLeft="30dp" android:layout_marginTop="-5dp"></ImageButton> 
     <ImageButton android:layout_height="wrap_content" 
      android:layout_width="wrap_content" android:src="@drawable/tasto4" 
      android:id="@+id/tastoMod4" android:background="@null" 
      android:layout_marginLeft="30dp" android:layout_marginTop="-5dp"></ImageButton> 
    </LinearLayout> 
</LinearLayout> 

क्या आप मेरी मदद कर सकते हैं: इस एक्सएमएल है?

उत्तर

18

मुझे यकीन है कि नहीं कर रहा हूँ, लेकिन आप इस कोड का प्रयास करना चाहिए: -

youredittext.setOnEditorActionListener(new TextView.OnEditorActionListener() { 

    @Override 
    public boolean onEditorAction(TextView v, int keyCode, KeyEvent event) { 
     if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { 
      // hide virtual keyboard 
      InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); 
      imm.hideSoftInputFromWindow(youredittext.getWindowToken(), 0); 
      return true; 
     } 
     return false; 
    } 
}); 

मुझे आशा है कि यह मदद मिलेगी ..

+0

मैं कोशिश करूंगा! लेकिन इस तरह से यह केवल कुंजी दर्ज करेगा, अन्य सत्य नहीं होगा? – JackTurky

+0

मैंने अपना जवाब संपादित किया और मुझे लगता है कि आप उन सभी को OnEditorActionListener संलग्न करने का प्रयास करें। – Uttam

+0

सत्रटैग? क्या संपादन है? – JackTurky

0

बेस्ट तरीका यह है, एक्सएमएल फ़ाइल

में निम्नलिखित कोड जोड़ने के लिए है
android:imeOptions="actionDone" 

मुझे समझ में नहीं कर रहा हूँ कि लोगों को सुझाव जावा कोड अगर वे बेहतर विकल्प है

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