0
我正在开发一个应用程序,并在我的班级,我有4个选项卡,并且在每个选项卡内有列表视图。我想要显示数据到列表视图。我提供数组中的数据,但问题是当我的应用程序启动时,显示单个选项卡下的4个选项卡的数据。 bt当我在标签上一个一个的点击它显示正确的数据。在标签下的Android列表视图
这里是源代码..:
public class test extends TabActivity implements OnTabChangeListener
{
private static final String LIST_TAB_TAG = "News";
private static final String LIST_TAB_TAG2 = "List2";
private static final String LIST_TAB_TAG3 = "List3";
private static final String LIST_TAB_TAG4 = "List4";
private TabHost tabHost,tabHost1,tabHost2,tabHost3;
private ListView listView,listview2,listview3,listview4;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.clistview);
tabHost = (TabHost) findViewById(android.R.id.tabhost);
// setup must be called if you are not inflating the tabhost from XML
tabHost.setup();
tabHost.setOnTabChangedListener(this);
listView = (ListView) findViewById(R.id.list);
listview2 = (ListView) findViewById(R.id.list2);
listview3 = (ListView) findViewById(R.id.list3);
listview4 = (ListView) findViewById(R.id.list4);
// create some dummy coordinates to add to the list
List<String> list1Strings = new ArrayList<String>();
list1Strings.add("");
list1Strings.add("Item 2");
list1Strings.add("Item 3");
list1Strings.add("Item 4");
listView.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, list1Strings));
List<GeoPoint> pointsList2 = new ArrayList<GeoPoint>();
pointsList2.add(new GeoPoint((int)(464464645), (int)(979646664)));
pointsList2.add(new GeoPoint((int)(7976566), (int)(987464313)));
listview2.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, pointsList2));
List<GeoPoint> pointsList3 = new ArrayList<GeoPoint>();
pointsList3.add(new GeoPoint((int)(32.864*1E6), (int)(-117.2353*1E6)));
pointsList3.add(new GeoPoint((int)(37.441*1E6), (int)(-122.1419*1E6)));
listview3.setAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1, pointsList3));
List<GeoPoint> pointsList4 = new ArrayList<GeoPoint>();
pointsList4.add(new GeoPoint((int)(464464645), (int)(979646664)));
pointsList4.add(new GeoPoint((int)(7976566), (int)(987464313)));
listview4.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, pointsList4));
tabHost.addTab(tabHost.newTabSpec(LIST_TAB_TAG).setIndicator("News", getResources().getDrawable(R.drawable.newsicon)).setContent(new TabContentFactory()
{
public View createTabContent(String arg0) {
return listView;
}
}));
tabHost.addTab(tabHost.newTabSpec(LIST_TAB_TAG2).setIndicator("Opinion", getResources().getDrawable(R.drawable.opinionicon)).setContent(new TabContentFactory() {
public View createTabContent(String arg0) {
return listview2;
}
}));
tabHost.addTab(tabHost.newTabSpec(LIST_TAB_TAG3).setIndicator("Press", getResources().getDrawable(R.drawable.pressicon)).setContent(new TabContentFactory() {
public View createTabContent(String arg0) {
return listview3;
}
}));
tabHost.addTab(tabHost.newTabSpec(LIST_TAB_TAG4).setIndicator("My Stocks", getResources().getDrawable(R.drawable.mystockicon)).setContent(new TabContentFactory() {
public View createTabContent(String arg0) {
return listview4;
}
}));
//HACK to get the list view to show up first,
//tabHost.setCurrentTab(1);
//tabHost.setCurrentTab(0);
}
@Override
/*protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}*/
public void onTabChanged(String tabId) {
// TODO Auto-generated method stub
}
}
有机会你可以添加你的布局XML文件? – 2010-10-11 16:38:38
另外,是否有你扩展TabActivity的原因,但也解压缩tabhost和调用setup()?通常,只有在不是TabActivity的情况下才会调用安装程序。它看起来像你从我的博客上的地图活动的代码。我也有关于List活动的教程,可能会更容易遵循。 – 2010-10-11 16:42:37
对不起乔希见下面; – JonniBravo 2010-10-14 13:22:19