我无法与我的TabHost中的第一个标签进行交互

时间:2015-10-21 19:54:47

标签: android xml android-tabhost

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true">
    <TabHost
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/tabHost"
        android:layout_gravity="center_horizontal"
        android:background="#FFFFFF">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#F44336"/>
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <LinearLayout
                    android:id="@+id/tab1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical">
                    <AutoCompleteTextView
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/autoCompleteTextView"
                        android:imeOptions="actionNext"
                        android:layout_below="@+id/textView"
                        android:clickable="true"/>
                    <Button
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:id="@+id/bt"
                        android:text="@string/Buscar"/>
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:id="@+id/tv1"
                        android:text="@+id/text1"
                        android:textColor="#212121"/>
                    <Button
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:id="@+id/btnmapa"
                        android:text="@string/mapa"/>
                </LinearLayout>

这是tabHost中第一个标签(LinearLayour)中的xml。首先不能与此互动,但实际上我可以与其他人互动。有什么建议吗?

public class MainActivity extends Activity {
TabHost tabHost;
private static Button but1;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //Autocompletar búsqueda
    AutoCompleteTextView auto = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);

    String[] lineas = getResources().getStringArray(R.array.lineas_array);

    ArrayAdapter<String > adapter;
    adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,lineas);

    auto.setThreshold(1);
    auto.setAdapter(adapter);
    auto.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            // TODO Auto-generated method stub
            Toast.makeText(getApplicationContext(), (CharSequence) arg0.getItemAtPosition(arg2), Toast.LENGTH_LONG).show();
        }
    });
    auto.requestFocus();
    InputMethodManager imm = (InputMethodManager)this.getSystemService(Service.INPUT_METHOD_SERVICE);
    imm.showSoftInput(auto, 0);

    tabHost=(TabHost)findViewById(R.id.tabHost);

    //Tab1
    tabHost.setup();
    TabSpec ts1=tabHost.newTabSpec("Tab1");
    ts1.setIndicator("Paradas");
    ts1.setContent(R.id.tab1);
    tabHost.addTab(ts1);

这也是我的java代码,因为我认为它与我实现适合第一个标签的AutoCompleteTextView的方式有关。

0 个答案:

没有答案