2011-10-23 4 views
7

4 개의 편집 문구가있는 활동이 있으며 사용자가 4 개의 편집 문구 중 하나를 사용하기 위해 끝내면 키보드를 숨기려고합니다. 키보드에서 엔터를 클릭하면 또 다른 편집 문구가 표시되고 키보드는 여전히 남아 있지만 키보드를 숨겨야하므로 한 개의 편집 문구와 반드시 다른 문구 만 사용할 수 있습니다.Enter 키를 사용하여 키보드를 숨기는 방법

<?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> 

당신이 나를 도울 수 : 이 XML인가?

답변

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

나는 시도 할 것이다! 하지만이 방법으로 만 Enter 키를 오버라이드하고 다른 것은 참이 아닌가? – JackTurky

+0

나는 나의 대답을 편집했고, 나는 그들 모두에게 OnEditorActionListener를 붙이려 고 생각한다. – Uttam

+0

sessionTag? edittext는 무엇입니까? – JackTurky

0

이 작업을 수행하는 가장 좋은 방법은 XML 파일

에서 다음과 같은 코드를 추가하는 것입니다
android:imeOptions="actionDone" 

이해가 안하고 왜 사람들 제안 자바 코드들은 더 나은 옵션이있는 경우

관련 문제