开发者

can I have multiple lists in a listview activity in android

开发者 https://www.devze.com 2023-04-11 14:38 出处:网络
Is it开发者_运维知识库 possible that in 1 listactivity will handle multiple lists? YoavYes, This is possible. Have you tried?.

Is it开发者_运维知识库 possible that in 1 listactivity will handle multiple lists?

Yoav


Yes, This is possible. Have you tried?.

For example:----

  public class MyActivity1 extends Activity implements OnItemClickListener {
  ...
  public void onCreate(...) {
    ...
    myList1.setOnItemClickListener(this);
    myList2.setOnItemClickListener(this);
    ...
  }
  ...
  public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
   if (adapter.getId() == R.id.list1) {

       // handling mylist1

   } else if (adapter.getId() == R.id.list2) {

       // handling list2 
   }
   }
 }

May be helpful.....


One ListActivity can handle multiple list.. but u have to manage other list yourself.

Only one list with the id android:id/list will be managed by ListActivity where you can call things like Activity.getAdapter helper method and also supply an empty view with the id of android:id/empty to display when the list is empty.


You can try this

public class Lists extends Activity
{
   ListView ls1;
   ListView ls2;

   public void onResume()
   {
    super.onResume();
        ls1=(ListView)findViewById(R.id.listW1); 
        ls2=(ListView)findViewById(R.id.listW2); 
        // here is your code

        // create the adapters
        SimpleAdapter adapter1 = new SimpleAdapter(this, strList1, R.layout.list_row_waiting,
                new String[]{"src","dest","date","time"},
                new int[]{R.id.from_list_waiting,R.id.to_list_waiting,R.id.date_list_waiting,R.id.time_list_waiting});  

        SimpleAdapter adapter2 = new SimpleAdapter(this, strList2, R.layout.list_row_waiting, new String[]{"src","dest","date","time"},
                new int[]{R.id.from_list_waiting,R.id.to_list_waiting,R.id.date_list_waiting,R.id.time_list_waiting});  

        ls1.setAdapter(adapter1);
        ls2.setAdapter(adapter2);

}

Hope it will help

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号