Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 选项卡主机列表适配器和列表_Android_List_Listview_Adapter_Android Tabhost - Fatal编程技术网

Android 选项卡主机列表适配器和列表

Android 选项卡主机列表适配器和列表,android,list,listview,adapter,android-tabhost,Android,List,Listview,Adapter,Android Tabhost,嗨 我的tabhost有问题,我真的不明白为什么。 “我的选项卡主机”包含4个列表视图,并在每个选项卡中显示一个列表。有时,当我更改选项卡(单击“新建选项卡”)时,内容不会更改或冻结。我已经在几个设备上试过了,问题仍然存在 这是我的密码: public class TabHostActivity extends TabActivity implements OnTabChangeListener { private TabHost mTabHost; private Resou

嗨 我的tabhost有问题,我真的不明白为什么。 “我的选项卡主机”包含4个列表视图,并在每个选项卡中显示一个列表。有时,当我更改选项卡(单击“新建选项卡”)时,内容不会更改或冻结。我已经在几个设备上试过了,问题仍然存在

这是我的密码:

public class TabHostActivity extends TabActivity implements OnTabChangeListener {

    private TabHost mTabHost;
    private Resources mResources;
    private SharedPreferences prefs;
    private ListView lv1;
    private ListView lv2;
    private ListView lv3;
    private ListView lv4;
    private String servicio = "teatre"; // por ahora luego varia segun los
                                        // eventos
    private String servicio2 = "expos";
    private static final String Tab_title1 = "Agenda";
    private static final String Tab_title3 = "Teatre";
    private static final String Tab_title4 = "Exposicions";
    private static final String Tab_title2 = "Cinema";
    private EventsList eventsL;
    private ArrayList<Event> events;
    private EventAdapterAprop mAdapter;
    private EventAdapterAprop mAdapter2;
    private EventAdapterAprop mAdapter3;
    private EventAdapterAprop mAdapter4;
    private EventsList eventsL3;
    private EventsList eventsL4;
    private ArrayList<Event> events3;
    private ArrayList<Event> events4;
    private EventsList eventsL2;
    private ArrayList<Event> events2;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tabhost);

        mTabHost = getTabHost();
        lv1 = (ListView) findViewById(R.id.list1);

        lv2 = (ListView) findViewById(R.id.list2);
        lv3 = (ListView) findViewById(R.id.list3);
        lv4 = (ListView) findViewById(R.id.list4);

        Bundle b = getIntent().getExtras();

        //agenda
        try{
        eventsL = b.getParcelable("events");
        events = new ArrayList<Event>();

        for (int i = 0; i < eventsL.size(); i++) {
            events.add(eventsL.get(i));
        }


            mAdapter = new EventAdapterAprop(this, events);
        } catch (Exception ex) {
            ex.printStackTrace();
            mAdapter = new EventAdapterAprop(this, crearVacio());
        }
        // teatro

        try{
        eventsL3 = b.getParcelable("events3");
        events3 = new ArrayList<Event>();

        for (int i = 0; i < eventsL3.size(); i++) {
            events3.add(eventsL3.get(i));
        }


            mAdapter3 = new EventAdapterAprop(this, events3);
        } catch(Exception ex) {
            mAdapter3 = new EventAdapterAprop(this, crearVacio());
            ex.printStackTrace();
        }


        // expos
        try{
        eventsL4 = b.getParcelable("events4");
        events4 = new ArrayList<Event>();

        for (int i = 0; i < eventsL4.size(); i++) {
            events4.add(eventsL4.get(i));
        }

            mAdapter4 = new EventAdapterAprop(this, events4);
        } catch(Exception ex){
            mAdapter4 = new EventAdapterAprop(this, crearVacio());
            ex.printStackTrace();
        }

        // cine
        try{
        eventsL2 = b.getParcelable("events2");
        events2 = new ArrayList<Event>();

        for (int i = 0; i < eventsL2.size(); i++) {
            events2.add(eventsL2.get(i));
        }


            mAdapter2 = new EventAdapterAprop(this, events2);
        } catch(Exception ex) {
            mAdapter2 = new EventAdapterAprop(this, crearVacio());
            ex.printStackTrace();
        }

        //mAdapter2=new EventAdapterAprop(this, crearVacio());

        lv1.setAdapter(mAdapter);
        lv1.setTextFilterEnabled(true);
        lv1.computeScroll();

        lv2.setAdapter(mAdapter2);
        lv2.setTextFilterEnabled(true);
        lv2.computeScroll();

        lv3.setAdapter(mAdapter3);
        lv3.setTextFilterEnabled(true);
        lv3.computeScroll();

        lv4.setAdapter(mAdapter4);
        lv4.setTextFilterEnabled(true);
        lv4.computeScroll();

        mTabHost.addTab(mTabHost.newTabSpec(Tab_title1)
                .setIndicator(Tab_title1).setContent(new TabContentFactory() {
                    public View createTabContent(String arg0) {
                        return lv1;
                    }
                }));
        mTabHost.addTab(mTabHost.newTabSpec(Tab_title2)
                .setIndicator(Tab_title2).setContent(new TabContentFactory() {
                    public View createTabContent(String arg0) {
                        return lv2;
                    }
                }));

        mTabHost.addTab(mTabHost.newTabSpec(Tab_title3)
                .setIndicator(Tab_title3).setContent(new TabContentFactory() {
                    public View createTabContent(String arg0) {
                        return lv3;
                    }
                }));
        mTabHost.addTab(mTabHost.newTabSpec(Tab_title4)
                .setIndicator(Tab_title4).setContent(new TabContentFactory() {
                    public View createTabContent(String arg0) {
                        return lv4;
                    }
                }));
    }

    public ArrayList<Event> crearVacio() {
        ArrayList<Event> arrayList = new ArrayList<Event>();
        Event e = new Event();
        e.setTitle("Cap esdeveniment correspon a la seva recerca");
        e.setDates("");
        e.setTimes("");
        e.setVenue("");
        arrayList.add(e);
        return arrayList;
    }

    @Override
    public void onTabChanged(String tabId) {
        // TODO Auto-generated method stub

    }

    }
公共类TabHostActivity扩展TabActivity实现OnTabChangeListener{
私有TabHost-mTabHost;
私人资源;
私人共享参考优先权;
私有ListView lv1;
私有ListView lv2;
私有ListView lv3;
私有ListView lv4;
私有字符串servicio=“teatre”//por ahora luego varia segun los
//事件
私有字符串servicio2=“expos”;
私有静态最终字符串选项卡_title1=“议程”;
私有静态最终字符串选项卡_title3=“Teatre”;
私有静态最终字符串选项卡_title4=“Exposicions”;
私有静态最终字符串选项卡_title2=“电影院”;
私人事件列表事件1;
私人ArrayList事件;
私人事件适配器Prop mAdapter;
私人事件适配器Prop mAdapter2;
私人事件适配器Prop Madapter 3;
私人事件适配器Prop mAdapter4;
私人事件列表事件3;
私人事件列表事件4;
私人ArrayList事件3;
私人ArrayList事件4;
私人事件列表事件2;
私人ArrayList事件2;
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.tabhost);
mTabHost=getTabHost();
lv1=(ListView)findViewById(R.id.list1);
lv2=(ListView)findViewById(R.id.list2);
lv3=(ListView)findViewById(R.id.list3);
lv4=(ListView)findViewById(R.id.list4);
Bundle b=getIntent().getExtras();
//议程
试一试{
eventsL=b.getParcelable(“事件”);
事件=新的ArrayList();
对于(int i=0;i
以及xml:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost" android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    xmlns:android1="http://schemas.android.com/apk/res/android">
    <LinearLayout android:orientation="vertical"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:background="@drawable/fonsbutxacadroid2">
        <TabWidget android:id="@android:id/tabs"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android1:background="@color/amarillo1"/>
        <FrameLayout android:id="@android:id/tabcontent"
            android:layout_width="fill_parent" android:layout_height="fill_parent">
            <ListView android:id="@+id/list1" android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:layout_weight="1" 
                >
            </ListView>
            <ListView android:id="@+id/list2" android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:layout_weight="1"
                >
            </ListView>
            <ListView android:id="@+id/list3" android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:layout_weight="1"
                >
            </ListView>
            <ListView android:id="@+id/list4" android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:layout_weight="1"
                >
            </ListView>
        </FrameLayout>
    </LinearLayout>
</TabHost>

怎么了


提前感谢。

将每个选项卡设为一个单独的活动解决了问题

布局示例:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
xmlns:android1="http://schemas.android.com/apk/res/android" 
android1:id="@+id/@android:id/tabhost" android1:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:padding="5dp">
    <TabWidget android:id="@android:id/tabs"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"/>
    <FrameLayout android:id="@android:id/tabcontent"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        >           
    </FrameLayout>
</LinearLayout>

使每个选项卡成为一个单独的活动
public class AllActivitiesTabs extends TabActivity {

private static final String Tab_title = "Nueva";
private TabHost mTabHost;
private TextView txtTabInfo;

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


mTabHost = getTabHost();

TabSpec spec;
//to add one tab activity       
txtTabInfo = new TextView(getApplicationContext());
txtTabInfo.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,         
LayoutParams.WRAP_CONTENT));
txtTabInfo.setBackgroundDrawable(getResources().getDrawable(
            R.drawable.tab_incidencia));
Intent intent = new Intent();
intent.setClass(this, ListActivityClass.class);
spec = mTabHost.newTabSpec(Tab_title).setIndicator(txtTabInfo)
            .setContent(intent);
mTabHost.addTab(spec);

//do the same for other activities
//your activities can be lists or something else:


txtTabInfo2 = new TextView(getApplicationContext());
txtTabInfo2.setBackgroundDrawable(getResources().getDrawable(
            R.drawable.tab_solucions));
txtTabInfo2.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,     
LayoutParams.WRAP_CONTENT));
intent = new Intent();
intent.setClass(this, FirstGroup.class);

spec = mTabHost.newTabSpec(Tab_title2).setIndicator(txtTabInfo2)
            .setContent(intent);
mTabHost.addTab(spec);
}
}