English 中文(简体)
习俗清单 观点在通知后不核对所有检查箱 数据
原标题:Custom ListView doesn t uncheck all checkboxes after notifyDataSetChanged

I m 正在开发一种3.1套应用。 I m 非常新颖的发展。

我有一个<代码>ListActative,其中项目的定义如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <CheckBox
        android:id="@+id/itemCheckBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</LinearLayout>

http://www.un.org/Depts/DGACM/index_french.htm 用户可以选择一种或多种形式(检查<代码>check Box)并下载。

当表格被下载时,我想从名单上删除。 为此,我使用<代码>更新的表格编号<>代码>,<>FormAdapter:

    public class FormAdapter extends ArrayAdapter<Form>
    {
        private Context context;
        private int layoutResourceId;
        private ArrayList<Form> forms;
        private ArrayList<Integer> checkedItemsPosition;
        private Button downloadButton;

        public ArrayList<Integer> getCheckedItemsPosition()
        {
            return checkedItemsPosition;
        }

        public String[] getSelectedFormsId()
        {
            String[] ids = new String[checkedItemsPosition.size()];
            int i = 0;
            for(Integer pos : checkedItemsPosition)
            {
                Form f = forms.get(pos.intValue());
                ids[i] = f.FormId;
                i++;
            }
            return ids;
        }

        /**
         * Called when selected forms has been downloaded and save it locally correctly.
         */
        public void updateFormsNotDownloaded()
        {
            for(Integer pos: checkedItemsPosition)
                remove(forms.get(pos.intValue()));
            checkedItemsPosition.clear();
            notifyDataSetChanged();
        }

        public FormAdapter(Context context, int textViewResourceId,
                ArrayList<Form> objects, Button downloadButton)
        {
            super(context, textViewResourceId, objects);

            this.context = context;
            this.layoutResourceId = textViewResourceId;
            this.forms = objects;
            this.checkedItemsPosition = new ArrayList<Integer>();
            this.downloadButton = downloadButton;
        }

        @Override
        public int getCount()
        {
            return forms.size();
        }
        @Override
        public View getView(final int position, View convertView, ViewGroup parent)
        {
            Log.v("FormAdapter", "getView.postion: " + position);
            View row = convertView;
            if (row == null)
            {
                LayoutInflater inflater = ((Activity)context).getLayoutInflater();
                row = inflater.inflate(layoutResourceId, parent, false);
            }

            Form f = forms.get(position);
            if (f != null)
            {
                CheckBox checkBox = (CheckBox)row.findViewById(R.id.itemCheckBox);
                if (checkBox != null)
                {
                    checkBox.setText(f.Name);
                    checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener()
                    {
                        public void onCheckedChanged(CompoundButton buttonView,
                                boolean isChecked)
                        {
                            //Form f = forms.get(position);
                            if (isChecked)
                            {
                                //checkedItems.add(f.FormId);
                                checkedItemsPosition.add(new Integer(position));
                            }
                            else
                            {
                                //checkedItems.remove(checkedItems.indexOf(f.FormId));
                                int index = checkedItemsPosition.indexOf(new Integer(position));
                                if (index > -1)
                                    checkedItemsPosition.remove(index);
                            }
                            downloadButton.setEnabled(checkedItemsPosition.size() > 0);
                        }
                    });
                }
            }

            return row;
        }
    }
}

我有以下名单:

  1. Form 1. (Checked)
  2. Form 2.
  3. Form 3.

用户选择表1,在当地节省表格时,请参见:

  1. Form 2. (Checked)
  2. Form 3.

为什么要检查表2? 我怎么能够阻止这一切?

最佳回答

你们应当检查一下,看看是否应当检查这一职位,并人工确定每个职位的核实价值。 我看不到你正在做的事情。

页: 1

//we set the OnCheckedChangeListener to null so that setting the checkbox value doesn t trigger the checkedChangelistener
//this may or may not be relevant for your project
checkBox.setOnCheckedChangeListener(null); 
checkbox.setChecked(checkedItemsPosition.contains(position));
checkBox.setText(f.Name);
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
      {
        //the rest of your code here
      }
}
问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签