How can I refresh the list after changes?

旧时模样 提交于 2019-12-12 06:24:04

问题


I use my ArrayAdapter expanded getView method. I change CheckBox but the ListView does not refresh

my source

@Override
    public View getView(int position, View convertView, ViewGroup parent) {

        // Planet to display
        UrlItem urlItem = (UrlItem) this.getItem(position);
        ViewHolder viewHolder = null;

        if (convertView == null) {

            convertView = inflater.inflate(R.layout.database_table_item, null);
            viewHolder = new ViewHolder();
            viewHolder.checkbox = (CheckBox) convertView
                    .findViewById(R.id.checkBox1);



            viewHolder.checkbox
                    .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                        public void onCheckedChanged(CompoundButton buttonView,
                                boolean isChecked) {

                            int getPosition = (Integer) buttonView.getTag();
                            DatabaseTable.setPosition(getPosition);


                            for (int i = 0; i < UrlItems.size(); i ++ ) {

                                UrlItems.get(i).setUse(false);

                            }

                            UrlItems.get(getPosition).setUse(isChecked);


                        }
                    });

How can I refresh the list after changes ??

for your information in the manifest set

<activity
            android:name=".DatabaseTable"
            android:label="database_table" android:windowSoftInputMode="adjustPan" >

See the link for the upgrade using the button "selectAll" I have exact same idea but without the button selectAll

http://pastebin.com/PgNeDnXq


回答1:


adapter.notifyDataSetChanged(); // to notify the adapter that your data has been updated

Note: If you get any errors with the above line, you could try the following code (where mListView is the name of my ListView object)

((BaseAdapter) mListView.getAdapter()).notifyDataSetChanged(); 

Another way would be to invalidate the List so that it is redrawn form the updated data set once again.

mListView=(ListView) findViewById(R.id.MyListView);
mListView.invalidate();



回答2:


mAdapter.notifyDataSetChanged();

notify that the data set have changed ; )



来源:https://stackoverflow.com/questions/11972259/how-can-i-refresh-the-list-after-changes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!