0
當我運行我的應用程序時。我在底部有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);
}
}
嗨@丹尼爾,請在設置問題標題時務必小心。準確度越高,回覆的發送速度就越快。也嘗試格式化代碼,以便它不需要滾動框;) – Merlin
如何創建標籤?你可以發佈該代碼嗎? –