Android的列表视图与复选框?视图、复选框、列表、Android

由网友(余生敬安凉)分享简介:我开发它采用列表视图的复选框的应用程序,可以考虑有 10项在列表视图项,默认情况下该复选框被选中,直到现在每一件事情是工作的罚款,我在这里是我的问题,当我的取消选中任何复选框在列表视图的全列表视图必须刷新 I am developing an application which uses list view with...

我开发它采用列表视图的复选框的应用程序,可以考虑有 10项列表视图项,默认情况下该复选框被选中,直到现在每一件事情是工作的罚款,我在这里是我的问题,当我的取消选中任何复选框在列表视图的全列表视图必须刷新

I am developing an application which uses list view with check-boxes,consider there are 10 items on list-view items,And by default in that check boxes are checked,Until now every thing is working fine for me here is my problem,When I uncheck any check-box in list-view whole list-view need to be refresh.

推荐答案

尼基尔只是记住,定义自定义适配器是一次练习,一旦你定义和理解正确,那么你可以自定义任何意见样的ListView,GridView控件,画廊,微调。因此,通过下面的答案正确。

Nikhil just keep in mind that defining a custom adapter is one time practice, once you define and understand it properly then you can customize any views like ListView, GridView, Gallery, Spinner. So go through the below answer properly.

有关规定使用复选框(或任何视图)ListView控件,你必须定义自己的自定义适配器。为了定义自定义适配器,请按照下列步骤操作:

For defining ListView with CheckBox (or any View), you have to define your own custom adapter. For defining custom adapter, follow below steps:

定义自定义行文件(重新presents您的列表视图的每一个项目) 定义一个适配器类,并扩展了BaseAdapter。 充气上面一行xml文件这个适配器类的getView()方法中。

在你的情况,

<RelativeLayout>
   <TextView>
   <CheckBox>
</RelativeLayout>

2楼和放大器;第3步:(定义自定义适配器类)

public class MyListViewAdapter extends BaseAdapter
{
  ....
  ....


   static class ViewHolder {
        protected TextView text;
        protected CheckBox checkbox;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = null;
        if (convertView == null) {
            LayoutInflater inflator = context.getLayoutInflater();
            view = inflator.inflate(R.layout.rowbuttonlayout, null);
            final ViewHolder viewHolder = new ViewHolder();
            viewHolder.text = (TextView) view.findViewById(R.id.label);
            viewHolder.checkbox = (CheckBox) view.findViewById(R.id.check);
            viewHolder.checkbox
                    .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                        @Override
                        public void onCheckedChanged(CompoundButton buttonView,
                                boolean isChecked) {
                            Model element = (Model) viewHolder.checkbox
                                    .getTag();
                            element.setSelected(buttonView.isChecked());

                        }
                    });
            view.setTag(viewHolder);
            viewHolder.checkbox.setTag(list.get(position));
        } else {
            view = convertView;
            ((ViewHolder) view.getTag()).checkbox.setTag(list.get(position));
        }
        ViewHolder holder = (ViewHolder) view.getTag();
        holder.text.setText(list.get(position).getName());
        holder.checkbox.setChecked(list.get(position).isSelected());


.......
.......
}
阅读全文

相关推荐

最新文章