在一个简单的列表禁止复选框查看多的选择呢? [英] disable checkbox in a simple list view multi choice?

查看:184
本文介绍了在一个简单的列表禁止复选框查看多的选择呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有禁用一个简单的列表视图选择题复选框(prevent被点击盒子)的一种手段?

我简单地定义一个标准的ListView在我的XML布局,设置多选择,当用户检查一个盒子我想禁用/锁定选项(一个onClick后)。

伊夫试图用玩:theCheckBox.setClickable(假);
但不知道如何从我的简单列表视图得到theCheckBox?

什么想法?

感谢。

我的适配器是简单的:

 适配器=新ArrayAdapter<串GT;(这一点,android.R.layout.simple_list_item_multiple_choice,this.ingredientArray);
itemList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
itemList.setAdapter(适配器);


解决方案

您可以覆盖你 getView 在匿名 ArrayAdapter 类,并应用视图的禁用它。

示例:

  ArrayAdapter适配器=新ArrayAdapter<串GT;(这一点,android.R.layout.simple_list_item_multiple_choice,this.ingredientArray){
        公共查看getView(INT位置,查看convertView,父母的ViewGroup){
            最后CheckedTextView CTV =(CheckedTextView)convertView.findViewById(android.R.id.text1);
            ctv.setOnClickListener(新OnClickListener(){                @覆盖
                公共无效的onClick(视图v){
                    如果(ctv.isChecked())
                        ctv.setClickable(假);
                }
            });
        };
    };
    itemList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    itemList.setAdapter(适配器);

编辑:

  ArrayAdapter<串GT;适配器=新ArrayAdapter<串GT;(这一点,android.R.layout.simple_list_item_multiple_choice,this.ingredientArray){
            公共查看getView(INT位置,查看convertView,父母的ViewGroup){                如果(convertView == NULL)
                {
                    视图V = getLayoutInflater()膨胀(android.R.layout.simple_list_item_multiple_choice,NULL);                    最后CheckedTextView CTV =(CheckedTextView)v.findViewById(android.R.id.text1);
                    ctv.setText(ingredientArray [位置]);                    ctv.setOnClickListener(新OnClickListener(){                        @覆盖
                        公共无效的onClick(视图v){
                            如果(!ctv.isChecked())
                            {
                                ctv.setChecked(真);
                            }
                        }                    });
                    返回伏;
                }                返回convertView;
            };
        };

Is there a means to disable a checkbox (prevent the box from being clickable) on a simple list view multiple choice?

I'm simply defining a standard listview in my xml layout, setting as multi choice and when the user checks a box I want to disable/lock the selection (after an onClick).

Ive tried playing with: theCheckBox.setClickable(false); but not sure how to get theCheckBox from my simple listview?

any ideas?

thanks.

My adapter is simple:

adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_multiple_choice, this.ingredientArray);
itemList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
itemList.setAdapter(adapter);

解决方案

You can override you getView in the anonymous ArrayAdapter class and apply the disabling of the view in it.

sample:

ArrayAdapter adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_multiple_choice, this.ingredientArray){
        public View getView(int position, View convertView, ViewGroup parent) {
            final CheckedTextView ctv = (CheckedTextView)convertView.findViewById(android.R.id.text1);
            ctv.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    if(ctv.isChecked())
                        ctv.setClickable(false);
                }
            });
        };
    };
    itemList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    itemList.setAdapter(adapter);

EDIT:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_multiple_choice, this.ingredientArray){
            public View getView(int position, View convertView, ViewGroup parent) {

                if(convertView == null)
                {
                    View v = getLayoutInflater().inflate(android.R.layout.simple_list_item_multiple_choice, null);

                    final CheckedTextView ctv = (CheckedTextView)v.findViewById(android.R.id.text1);
                    ctv.setText(ingredientArray[position]);

                    ctv.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            if(!ctv.isChecked())
                            {
                                ctv.setChecked(true);
                            }
                        }

                    });
                    return v;
                }

                return convertView;
            };
        };

这篇关于在一个简单的列表禁止复选框查看多的选择呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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