簡體   English   中英

具有更多ListView的AdapterView.OnItemClickListener

[英]AdapterView.OnItemClickListener with more ListView

我在一個片段上有2個ListView,我想知道我是否可以為實現AdapterView.OnItemClickListener的同一個類設置。

我的意思是,Android文檔說:

public abstract void onItemClick (AdapterView<?> parent, View view, int position, long id)

Added in API level 1
Callback method to be invoked when an item in this AdapterView has been clicked.

Implementers can call getItemAtPosition(position) if they need to access the data associated with the selected item.

Parameters
parent  The AdapterView where the click happened.
view    The view within the AdapterView that was clicked (this will be a view provided by the adapter)
position    The position of the view in the adapter.
id  The row id of the item that was clicked.

所以我想我可以選擇不同的ListView調用onClick by Parent(AdapterView,其中點擊發生)..

現在我該如何識別ListView? 有沒有辦法解決/案件? 或者我需要創建不同的類(我也知道也可以是匿名的)實現onItemClickListener並設置為不同的ListView不同的AdapterView.onItemClickListener?

好的我解決了:

private class myClass implements AdapterView.OnItemClickListener {

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {
        // TODO Auto-generated method stub

        switch(parent.getId()) {
        case R.id.listview1:            
            break;
        case R.id.listview2:
            break;
        }
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM