开发者

multiple Lists in a ListActivity and onListItemClick feature (or workaround?)

开发者 https://www.devze.com 2023-03-25 03:25 出处:网络
I know that ListActivity gives me the possibility to use onListItemClick. On the other hand in a normal Activity i can include multiple lists and make easy switching+animation through a ViewFlipper.

I know that ListActivity gives me the possibility to use onListItemClick. On the other hand in a normal Activity i can include multiple lists and make easy switching+animation through a ViewFlipper.

So. Can i make it work alltogether?

[Solved] Yes! ... implements are the kings. Deleted my code to minimize confusion开发者_运维百科.


Have you tried having your Activity implement OnItemClickListener and then set your lists' onItemClickListener to the activity? I.e.

public class MyActivity extends Activity implements OnItemClickListener {
    ...
    public void onCreate(...) {
        ...
        mList1.setOnItemClickListener(this);
        mList2.setOnItemClickListener(this);
        ...
    }
    ...
    public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
       if (adapter.getId() == R.id.list1) {
           // Handle list1 click event
       } else if (adapter.getId() == R.id.list2) {
           // Handle list2 click event
       }
    }
}
0

精彩评论

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

关注公众号