calling listactiviy from tabactivity in android

旧巷老猫 提交于 2019-12-10 23:06:56

问题


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.

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 Class

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);    


}

}


回答1:


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
            }
});


来源:https://stackoverflow.com/questions/3287606/calling-listactiviy-from-tabactivity-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!