在动态标签内容的Andr​​oid动态标签 [英] Dynamic tab in android with dynamic tab content

查看:111
本文介绍了在动态标签内容的Andr​​oid动态标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想在动态Android和每个选项卡下创建选项卡我有一个列表视图。所以我想在ListView的内容也动态地改变。我怎样才能做到这一点?

Hi, I want to create Tab dynamically in android and under each tab I have one listview. So I want the content of the listview to also change dynamically. How can I do this ?

在此先感谢。任何帮助将AP preciated。

Thanks in advance. Any help will be appreciated.

推荐答案

我看到了另一个论坛上一个code和清理它一点点。要做到你需要什么你就必须改变ts1.setContent和ts2.setContent里面的东西。

I saw a code on another forum and cleaned it up a little. To do what you need you'll have to change the stuff inside of ts1.setContent and ts2.setContent

Main_screen.java

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class Main_screen extends Activity{

    private ListView ls1;
    private ListView ls2;   
    private TabHost myTabHost;

    @Override
    public void onCreate(Bundle icicle)
    {
        super.onCreate(icicle);
        setContentView(R.layout.main);

        myTabHost = (TabHost)this.findViewById(R.id.th_set_menu_tabhost); 
        myTabHost.setup();

        ls1 = new ListView(Main_screen.this);       
        TabSpec ts1 = myTabHost.newTabSpec("TAB_TAG_1");
        ts1.setIndicator("Tab1");
        ts1.setContent(new TabHost.TabContentFactory(){
            public View createTabContent(String tag)
            {                                   
                ArrayAdapter<String> adapter = new ArrayAdapter<String>(Main_screen.this,android.R.layout.simple_list_item_1,new String[]{"item1","item2","item3"});
                ls1.setAdapter(adapter);    
                return ls1;
            }       
        });
        myTabHost.addTab(ts1);

        ls2 = new ListView(Main_screen.this);
        TabSpec ts2 = myTabHost.newTabSpec("TAB_TAG_2");
        ts2.setIndicator("Tab2");
        ts2.setContent(new TabHost.TabContentFactory(){
            public View createTabContent(String tag)
            {                                   
                ArrayAdapter<String> adapter = new ArrayAdapter<String>(Main_screen.this,android.R.layout.simple_list_item_1,new String[]{"item4","item5","item6"});
                ls2.setAdapter(adapter);    
                return ls2;
            }       
        });     
        myTabHost.addTab(ts2);
    }       
}

的main.xml
     
    

main.xml

     <TabWidget 
          android:id="@android:id/tabs" 
          android:layout_width="fill_parent" 
          android:layout_height="64dip" />

     <FrameLayout 
          android:id="@android:id/tabcontent" 
          android:layout_width="fill_parent" 
          android:layout_height="fill_parent"
          android:paddingTop="75dip">  

          <ListView
              android:id = "@+id/danhsach"
              android:layout_width="fill_parent" 
              android:layout_height="fill_parent" />

     </FrameLayout> 
</TabHost>

这篇关于在动态标签内容的Andr​​oid动态标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆