如何知道这是点击一个特定的ListView项内查看这是、ListView

2023-09-04 13:24:12 作者:琵琶半掩的美人脸°

我有一个的ListView 与一个 BaseAdapter 导出自己的自定义适配器。在的ListView 每个项目都有,例如 ImageView的子项和的TextView

我怎么能知道用户点击这些子项中的哪一个?是否有可能附着在 getView 功能的监听器,例如,或者可以说是一个问题?

/亨里克

编辑:目前,我有一个 onItemClick ,其中包含的ListView 的活动。有没有知道哪些子项在ListView中的特定项目已经被通过检查PARAMS pssed $ P $什么好办法 onItemClick

  @覆盖
公共无效onItemClick(适配器视图<>一种,视图V,INT POS,长I​​D){
。
。
}
 

解决方案

您可以做到这一点。您需要修改你的getView方法:

  @覆盖
公共查看getView(最终诠释的立场,观点行,最终的ViewGroup父){
    ...
    YourWrapper包装= NULL;
    如果(行== NULL){
        行= getLayoutInflater()膨胀(R.layout.your_row,父母,假)。
        包装=新YourWrapper(行);
        row.setTag(包装);
    } 其他 {
        包装=(YourWrapper)row.getTag();
    }

    wrapper.yourSubView.setOnClickListener(新View.OnClickListener()
    {
    @覆盖
    公共无效的onClick(视图v){
        // 做一点事
    }
    ...
}
 
请问如何关闭outlook的已读邮件回执

I'm having a ListView with my own custom adapter derived from a BaseAdapter. Each item in the ListView has sub items such as ImageView and TextView.

How can I know which one of these sub items the user clicked? Is it possible to attach a listener in the getView function for example, or could that be a problem?

/ Henrik

Edit: Currently I have a onItemClick in the Activity which contains the ListView. Is there any good way to know which sub item in a specific item in the ListView which has been pressed by checking the params in the onItemClick.

@Override 
public void onItemClick(AdapterView<?> a, View v, int pos, long id) {
.
.
}

解决方案

You can do it. You need to modify your getView method:

@Override
public View getView(final int position, View row, final ViewGroup parent) {
    ...     
    YourWrapper wrapper = null;
    if (row == null) {
        row = getLayoutInflater().inflate(R.layout.your_row, parent, false);
        wrapper = new YourWrapper(row);
        row.setTag(wrapper);
    } else {
        wrapper = (YourWrapper) row.getTag();
    }

    wrapper.yourSubView.setOnClickListener(new View.OnClickListener()   
    {               
    @Override
    public void onClick(View v) {
        // do something
    }
    ...
}