我实现了一个标签布局,其中包含四个标签,每个标签包含一个列表视图。我之前使用的是listview的相同设置但不在tab主机下,它运行正常,即;单击列表项时,将启动新活动。但是现在列表既不可点击也不可滚动。现在,当我单击所有选项卡一次然后尝试滚动/单击行时,它完全正常。请让我知道我如何启用这两个。代码如下
tabHost = (TabHost) findViewById(android.R.id.tabhost);
tabHost.setup();
tabHost.setOnTabChangedListener(this);
list = (ListView) findViewById(R.id.listAll);
list.setEmptyView((TextView) findViewById(R.id.empty));
//list for all
tabHost.addTab(tabHost.newTabSpec(LIST_ALL).setIndicator("All Events").setContent(new TabContentFactory() {
public View createTabContent(String arg0) {
try{
Event event = new Event();
final String [] eventTitleArray = new String[XmlParser.eventsList.size()];
String [] eventDateArray = new String[XmlParser.eventsList.size()];
String [] eventImageLinkArray = new String[XmlParser.eventsList.size()];
for(int i=0;i<XmlParser.eventsList.size();i++){
event = XmlParser.eventsList.get(i);
eventTitleArray[i] = event.getTitle();
if(event.getDistance()!=0.0)
eventDateArray[i] = event.getsDate() +" - " +Double.toString(event.getDistance())+"mi";
else
eventDateArray[i] = event.getsDate();
eventImageLinkArray[i] = event.getImageLink();
Log.i(tag , "event detail"+event.getTitle());
}
list=(ListView)findViewById(R.id.listAll);
adapter= new LazyAdapter(HomeActivity.this, eventTitleArray,eventDateArray,eventImageLinkArray);
list.setAdapter(adapter);
list.setFocusable(false);
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
Intent intent = new Intent(HomeActivity.this, DisplayActivity.class);
Bundle b = new Bundle();
System.out.println("position in list:"+position);
System.out.println("title name in the list:"+eventTitleArray[position]);
b.putString("eventTitle", eventTitleArray[position]);
intent.putExtras(b);
startActivity(intent);
Toast.makeText(getApplicationContext(), "Detailed view for the Event", Toast.LENGTH_SHORT).show();
}
});
}
catch(Exception e){
e.printStackTrace();
}
return list;
}
}));
tabHost.addTab(tabHost.newTabSpec(LIST_TODAY).setIndicator("Events Today").setContent(new TabContentFactory() {
public View createTabContent(String arg0) {
return list;
}
}));
答案 0 :(得分:0)
您是否在Layout XML文件中将ListView标记为可点击?
看起来应该是这样的:
<ListView
android:id="@+id/MyListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"/>
答案 1 :(得分:0)
我刚刚做了这个,现在列表完全正常。
tabHost.setCurrentTab(3);
tabHost.setCurrentTab(2);
tabHost.setCurrentTab(1);
tabHost.setCurrentTab(0);