ฉันมีปัญหากับออโต้โฟกัสใน tabhost ฉันต้องแสดง softinput และโฟกัสใน editText เมื่อฉันเปิดแท็บนั้น (ด้วยข้อความแก้ไขนั้น) อธิบายได้ดีขึ้นด้วยรูปภาพถัดไป:
ในแท็บเดียวฉันมีเลย์เอาต์นั้น แต่เมื่อฉันเปิดมัน editText จะไม่ได้รับการโฟกัส ฉันทำมันได้ไม่ดีนักในการเปิดโปรแกรม editText เมื่อแท็บแสดงขึ้น แต่พฤติกรรมของมันเอาแน่เอานอนไม่ได้และมันจะทำงานเพียงครั้งที่สองหรือสามเท่านั้น
สิ่งที่ฉันต้องการคือทำโดยอัตโนมัติ เหมือนที่มักจะทำกับ android บน 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>
จากนั้นฉันก็มีกิจกรรมในกลุ่มกิจกรรม แต่ฉันคิดว่ามันต้องไม่เป็นปัญหาสำหรับออโต้โฟกัส โดยพื้นฐานแล้วนี่คือสิ่งที่ฉันทำกับเลย์เอาต์นั้น:
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);
...
}
...
}
ขอบคุณสำหรับการอ่านความช่วยเหลือทั้งหมดจะถูกอ่านอย่างซาบซึ้ง