我有两个listview
内部类,我不想为每个OnClickListener
实现listview
,而是希望该类实现OnClickListener
并处理listview OnClicklistener在单个覆盖方法OnClickListener
中。
任何人都可以提供帮助。
答案 0 :(得分:4)
class ListViewContainer implements AdapterView.OnItemClickListener{
ListView listView1;
ListView listView2;
private void someMethod(){
listView1.setOnItemClickListener(this);
listView2.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if(parent == listView1){
//Do Listview 1 things
}else if(parent == listView2){
//Do Listview 2 things
}
}
}
答案 1 :(得分:0)
private AdapterView.OnItemClickListener getItemClickListener(){
return new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
};
}
答案 2 :(得分:0)
private AdapterView.OnItemClickListener listener = new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
};
...
listView1.setOnItemClickListener(listener);
listView2.setOnItemClickListener(listener);