AdapterView.OnItemClickListener更多的ListView [英] AdapterView.OnItemClickListener with more ListView

查看:457
本文介绍了AdapterView.OnItemClickListener更多的ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2的ListView在一个片段,我不知道如果我能为实现AdapterView.OnItemClickListener同级别设置。

I have 2 ListView on a single fragment and I wonder if I can set for both same class that implements AdapterView.OnItemClickListener.

我的意思是,Android的文件说:

I mean, Android Documentation says:

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.

所以,我想,我可以选择调用的onClick由家长不同的ListView(适配器视图点击的地方发生了)。

So I suppose that I can choose different ListView that invoked onClick by Parent (AdapterView where click happened)..

现在我怎么能确定的ListView?有没有一种方法来swicth /箱?或者我需要建立不同​​的类(也可以是匿名的,我知道),实现onItemClickListener并设置为型动物的ListView型动物AdapterView.onItemClickListener?

Now how can I identify ListView? is there a way to swicth / case? or I need to create different class (can also be anonymous I know) that implements onItemClickListener and set to differents ListView differents 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;
        }
    }
}

这篇关于AdapterView.OnItemClickListener更多的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆