2

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


}

}

Girish
  • 605
  • 2
  • 7
  • 10
  • Could you please elaborate on the exact problem you are facing? Right now I do not see any issue. Using a ListActivity as a tab should work out of the box. – Thilo-Alexander Ginkel Jul 20 '10 at 06:58
  • @tg, I have attached mine code for the app, which consists of 2 tabs, and a listview – Girish Jul 20 '10 at 09:42
  • What is the problem? Can't you set a click listener or the ListView doesn't appear at all? – Francesco Laurita Jul 20 '10 at 10:19
  • My issue, i am unable to determine the click event. I am once again repeating the scenario. I have 2 tabs on my application , one tab consists of listview. I have data populated on listview. When i click on aparticular row i want the click event of the listview to be fired. – Girish Jul 20 '10 at 13:55

1 Answers1

2

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
            }
});
Rabas
  • 573
  • 1
  • 6
  • 13