本文介绍了针对Android tabactivity调用listactiviy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能通过标签活动来调用listactivity?基本上,我正在开发与3个标签,为此我使用tabactivity的应用程序。此外,我希望有一个列表视图的标签之一,所以我从listactivity的。
Is it possible to call listactivity through tab activity? Basically, I am developing an app with 3 tabs, for which I am using tabactivity. Furthermore, in one of the tabs I want a listview, so I have derived from listactivity.
现在我想在列表视图中确定的Click事件。我这么想吗?
Now I want the click event to be determined in the listview. Am i missing something?
public class Tabissue extends TabActivity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
TabHost host = getTabHost();
host.addTab(host.newTabSpec("Tab1").setIndicator("Tab1").setContent(new Intent(this,Tab1.class)));
host.addTab(host.newTabSpec("Tab2").setIndicator("Tab2").setContent(new Intent(this,Tab2.class)));
host.setCurrentTab(1);
}
}
TAB1类
public class Tab2 extends ListActivity
{
ListView list;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.tab2);
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();
map.put("Test1","####");
map.put("Test2", "India");
map.put("Time", "India time");
mylist.add(map);
map = new HashMap<String, String>();
map.put("Test1", "####");
map.put("Test2", "US");
map.put("Time","US time");
mylist.add(map);
map = new HashMap<String, String>();
map.put("Test1", "####");
map.put("Test2", "UK");
map.put("Time", "UK Time");
mylist.add(map);
ListAdapter mSchedule = new SimpleAdapter( this,
mylist,
R.layout.row,
new String[]
{
"India",
"US",
"UK"
},
new int[]
{
R.id.TRAIN_CELL,
R.id.FROM_CELL,
R.id.TO_CELL,
}
);
list.setAdapter(mSchedule);
}
}
推荐答案
在您的ListActivity设置onItemClickListener:
In your ListActivity set onItemClickListener:
getListView().setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> av, View v, int position,
long id) {
// Do your stuff here
}
});
这篇关于针对Android tabactivity调用listactiviy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!