i have implemented a tab layout that consists of four tabs each tab containing a listview. i was using the same setup of listview earlier but not under tab host and it worked fine, ie; when a list item was clicked a new activity would start. but now the list is neither clickable not scrollable.how ever now, when i click all the tabs once and then try to scroll/click rows, it works perfectly fine. please let me know how do i enable both. the code is as below
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() {
publ开发者_StackOverflow社区ic 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;
}
}));
Do you have the ListView marked as clickable in your Layout XML file?
It should look something like this:
<ListView
android:id="@+id/MyListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"/>
I just did this and the list works perfectly fine now.
tabHost.setCurrentTab(3);
tabHost.setCurrentTab(2);
tabHost.setCurrentTab(1);
tabHost.setCurrentTab(0);
精彩评论