当我运行我的应用程序时。我底部有4个标签(它是我创建它们的方式)。按下的每个选项卡将显示转发列表等...(应该发生)
现在我只是测试tab2按钮,它确实显示了列表,但无法点击任何其他选项卡。我无法弄清楚为什么。
这是我的代码:
//imports removed for brevity
//Second tab activity with the list activity
public class SecondActivity extends ListActivity{
/** Called when the activity is first created. */
static final String[] stops = new String[] {
"Pelham Parkway", "Yankees Stadium"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(
new ArrayAdapter<String>(this, R.layout.tab_test, stops)
);
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(),
((TextView) view).getText(),
Toast.LENGTH_SHORT).show();
}
});
}
}
标签代码部分:
是。这是我的标签代码。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
TabHost .TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, FirstActivity.class);
spec = tabHost.newTabSpec("First").setIndicator("First")
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, SecondActivity.class);
spec = tabHost.newTabSpec("Second").setIndicator("Second")
.setContent(new Intent(this,SecondActivity.class));
tabHost.addTab(spec);
intent = new Intent().setClass(this, ThirdActivity.class);
spec = tabHost.newTabSpec("Third").setIndicator("Third")
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, FourthActivity.class);
spec = tabHost.newTabSpec("Fourth").setIndicator("Fourth")
.setContent(intent);
tabHost.addTab(spec);
}
}
答案 0 :(得分:0)
没关系。我按照我想要的方式工作。我更正了我的xml参考相对锻炼。并使用findbyid将我的扩展ListActivity转换为Activity,指向我的列表。 花费最近几天让它正常工作。