获取在列表视图中点击按钮后的位置 [英] Get the position after click on button in a list view

查看:123
本文介绍了获取在列表视图中点击按钮后的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的适配器:

public View getView(int position, View convertView, ViewGroup parent)
    {
        ViewHolder holder;
        if(convertView==null)   
        {
            convertView = myInflater.inflate(R.layout.list, null);          
            holder = new ViewHolder();
            holder.text01 = (TextView) convertView.findViewById(R.id.Text01); 
            ((Button)convertView.findViewById(R.id.ListButonPlus)).setOnClickListener(this);
            convertView.setTag(holder);
        }else
        {
            holder = (ViewHolder) convertView.getTag();         
        }   
            return convertView;
        }

和是:

public void onClick(View v) 
{
    Toast.makeText(v.getContext(), "pouette",1000).show();
}

和我尝试吨得到谁包含我的按钮项的位置。

And I try t get the position of the item who contains my button.

如何传递在getView方法中的位置变量present我的onClick方法?
我有几个按钮,在我看来(项目视图)

How Can I pass the position variable present in the getView method to my onClick Method? I will have several button In my View (Item view)

感谢您

推荐答案

好吧,我发现,我通过我的位置到ViewHolder结果
我得到由递归函数的观点或看法parrent的标签ViewHolder。结果
有没有什么不同的方法?

Ok I found, I pass my position to the ViewHolder
and I get the ViewHolder from the tag of the view or parrent view by a recursive function.
Is there any different method?

public static class ViewHolder
    {
        private TextView text01;
        public int position;
    }
    public ViewHolder getViewHolder(View v)
    {
        if(v.getTag() == null)
        {
            return getViewHolder((View)v.getParent());
        }
        return (ViewHolder)v.getTag();
    }
    public void onClick(View v) {

        ViewHolder vh = getViewHolder(v);
                vh.position // Here I get position
       }

这篇关于获取在列表视图中点击按钮后的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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