2012-01-04 14 views
1

タブホストでオートフォーカスに問題があります。私はレイアウトすることを持っている一つのタブでsoftInputを表示する方法:不安定な動作のTabHostのEditText

enter image description here

:私は次の画像で説明し、より良い、softinput表示し、私は(それのEditTextで)そのタブを開いたときにEDITTEXTに焦点を当てる必要があります。しかし、私はそれを開くと、editTextはフォーカスを取得しません。タブが表示されているときにeditTextプログラムを開くのは間違っていますが、その動作は不安定で、2回目または3回目だけ実行されます。

私が望むのは、それを自動的に行うことです。それは、しばしばeditTextのアンドロイドを実行します。私は今のコードを置く:

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)。 –

関連する問題