2012-01-04 53 views
1

我在自動對焦的tabhost中遇到了一些問題。我需要顯示softinput並集中在EDITTEXT當我打開該選項卡(與EditText上),下一個畫面更好地解釋:如何在帶有不穩定行爲的TabHost中顯示softInput:EditText

enter image description here

在一個選項卡我有一個佈局。但是當我打開它時,editText不會獲得焦點。當標籤顯示時,我已經嚴重地打開了編輯editText的程序,但它的行爲是不穩定的,它只運行它的第二或第三次。

我想要的是自動執行,就像它經常在editText上執行android一樣。我把代碼現在:

tab_header.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout android:id="@+id/AbsoluteLayout01" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/search_bar" 
     android:layout_alignParentTop="true" 
     android:background="#FF000000" 
     android:layout_centerVertical="true" 
     android:orientation="horizontal" 
     android:paddingTop="6dip" 
     android:paddingBottom="6dip" 
     android:weightSum="4.0"> 
     <EditText android:id="@+id/search_field" 
      android:layout_height="45dip" 
      android:maxHeight="45dip" 
      android:layout_width="0dip" 
      android:layout_weight="3.1" 
      android:maxLines="1" 
      android:lines="1" 
      android:focusable="true" 
      android:focusableInTouchMode="true" 
      android:imeOptions="flagNoExtractUi" 
      android:textSize="18dip" 
      android:hint="@string/search_hint_text" 
      android:textColorHint="@color/edit_text_hint_search" 
      android:background="@drawable/et_search_field" 
      android:textColor="@color/edit_text" 
      android:layout_marginLeft="2dip" 
      android:layout_marginRight="0dip" 
      android:textColorHighlight="@color/edit_text_highlight" /> 
     <ImageButton android:text="Search" android:src="@drawable/ic_search_normal" android:id="@+id/search_button" 
      android:layout_width="0dip" 
      android:layout_height="45dip" 
      android:layout_weight="0.9" 
      android:scaleType="fitCenter" 
      android:layout_alignTop="@+id/search_field" 
      android:layout_alignBottom="@+id/search_field" 
      android:background="@drawable/button_generic" 
      android:layout_marginLeft="6dip" 
      android:layout_marginRight="2dip" 
      android:padding="10dip"/> 
    </LinearLayout> 
</RelativeLayout> 

以後,我活動到活動組,但我認爲它musn't是自動對焦的問題,基本上這就是我做什麼與該佈局:

public class SearchListActivity extends ListActivity implements OnScrollListener 
{ 
    ... 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     ... 
    View v = View.inflate(this, R.layout.tab_header, null); 
     getListView().addHeaderView(v); 
     ... 
    } 
    ... 
} 

感謝您的閱讀,所有幫助將被感激地閱讀。

回答

0

添加下面的重寫的onResume:

EditText ET=(EditText) findViewById (R.id.search_field); 
ET.requestfocus(); 
ET.SetText("Your soft input"); 
+0

的onResume火災,但軟輸入不與運行,既不\t \t((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE))showSoftInput(search_field。 ,0); – 2012-01-04 10:52:33