列表使用复选框 [英] list with checkBox

查看:110
本文介绍了列表使用复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表适配器,这是我的getView

I have a list adapter and this is my getView

public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null){
        convertView= myInflater.inflate(R.layout.index, null);
        holder= new ViewHolder();
        holder.textView= (TextView)convertView.findViewById(R.id.empty);
        holder.checkBox= (CheckBox) convertView.findViewById(R.id.Check);
        convertView.setTag(holder);
    }else{
        holder=(ViewHolder)convertView.getTag();
    }
    holder.textView.setText(lista.get(position));
    return convertView;
}

和本次活动的我的xml文件我有隐形的复选框......因为当我preSS底部我想出现的所有复选框在我的名单,我这样做...

and in my xml file of this activity i have the Checkbox invisible... because when I press the bottom I want that appears all checkbox in my list, I do this...

public boolean onOptionsItemSelected( MenuItem item){
    checkButton= (CheckBox) findViewById(R.id.Check);

        if (item.getItemId()== 2){
            for (int i =0; i< myAdapter.getCount(); i++){
                //myAdapter.getItemId(i);
                checkButton.setVisibility(View.VISIBLE);
            }

但有了这个只出现一个复选框在列表的顶部,而不是在列表中的其他元素......怎一个可以解决这个问题呢?

But with this only appears one checkBox in the top of the list and not in the other elements of the list... How a can fix this problem?

在此先感谢

推荐答案

使用

listview.setOnItemClickListener(new OnItemClickListener(){
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                long id) {
if(//ur condition)
{
view.findViewById(R.id.Check).setVisibility(CheckBox.VISIBLE);
}
//ur method
}

这篇关于列表使用复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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