2012-02-05 59 views
1

我有一個活動,它有一個EditText和一個ListView。 EditText可以用來過濾listview行。EditText竊取重點

問題是,當Activity加載時,默認情況下彈出鍵盤。我希望只有當用戶真正點擊文本框而不是默認情況下,鍵盤纔會出現。

Public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.filterablelayout); 

    filterText = (EditText) findViewById(R.id.search_box); 
    filterText.addTextChangedListener(filterTextWatcher); 

    filterText.setVisibility(View.INVISIBLE); 

    GetCategories(); 
} 

我的佈局XML是如下:

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

<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/selectcat" /> 

<EditText 
    android:id="@+id/search_box" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:hint="@string/categorytxthint" 
    android:inputType="text" 
    android:maxLines="1" /> 

<ListView 
    android:id="@android:id/list" 
    android:layout_width="fill_parent" 
    android:layout_height="0dip" 
    android:layout_weight="1" /> 

</LinearLayout> 
+0

我覺得這個問題是由http://stackoverflow.com/questions/1555109/stop-edittext-from-gaining解決-focus-AT-活動的啓動。現在測試。 – 2012-02-05 06:42:19

回答

0

我有這個問題我自己,它真的很煩人。您需要告訴系統隱藏軟鍵盤。 Android文檔說明了這一點:「用於hideSoftInputFromWindow(IBinder,int)的標誌表示如果軟輸入窗口未被用戶明確顯示,則應該只隱藏軟輸入窗口。」

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY); 
0

在清單中,把你的活動如下:

android:windowSoftInputMode="stateHidden"