Android的 - 任何的ListView项目所做的任何更改受到影响的第一个项目 [英] Android - Any change made to any of the ListView item is affected to the first item

查看:105
本文介绍了Android的 - 任何的ListView项目所做的任何更改受到影响的第一个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有显示的项目列表一个ListView。当我点击一个项目,我项目标记为已在我的数据库表中删除线。然后,我更新使用SimpleCursorAdapter,setViewBinder,setViewValue名单。

I have a ListView which displays a list of items. When I click on an item, I mark the item as striked in my database table. Then, I update the list using a SimpleCursorAdapter, setViewBinder, setViewValue.

我检查,如果删除线列设置为相应的项目,然后我更新的TextView罢工的项目。

I check if the striked column is set for a corresponding item, and then I update the TextView to strike the item.

在code低于

Cursor c = db.fetchAllNotes(id);
    startManagingCursor(c);

    String[] from = new String[] { DatabaseHandler.KEY_LIST };
    int[] to = new int[] { R.id.text1 };

    SimpleCursorAdapter notes =
        new SimpleCursorAdapter(this, R.layout.task_row, c, from, to);

    notes.setViewBinder(new SimpleCursorAdapter.ViewBinder() {

        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            // TODO Auto-generated method stub      
            text = (TextView) view.findViewById (R.id.text1);
            System.out.println("Item is "+ text.getText().toString());
            System.out.println("Item from cursor is " + cursor.getString(2));
            System.out.println("Striked value is " + Integer.parseInt(cursor.getString(3)));
            if(Integer.parseInt(cursor.getString(3)) == 1)
                text.setPaintFlags(textViewItem.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
            return false;
        }
    });
    setListAdapter(notes);

我在做什么错了?

What am I doing wrong?

推荐答案

我想这是因为意见中的ListView重用。尝试重置油漆标志时的观点并没有删除线:

I think it's because views are reused in ListView. Try to reset paint flags when view is not striked:

 if(Integer.parseInt(cursor.getString(3)) == 1){
     textViewItem.setPaintFlags(textViewItem.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
 } else {
     //resed paint flags
     textViewItem.setPaintFlags(textViewItem.getPaintFlags() & (~ Paint.STRIKE_THRU_TEXT_FLAG));
 }

编辑:
 我不知道如果我的explatation是corect。当你有上的ListView 10个项目其中只有5可见Android的创建(inflantes)只有5次。当您滚动列表中的一个新的项目将是可见的,但奥斯陆1就会消失,所以会有一个未使用的视图。西港岛线的Andr​​oid采取不使用的视图,用新的数据填充它,并用它来新出现的项目。我发现一些更多的信息 href=\"http://lucasr.org/2012/04/05/performance-tips-for-androids-listview/\">。

I am not sure if my explatation is corect. When You have 10 items on ListView and only 5 of them are visible android creates(inflantes) only 5 views. When you scroll list one new item will be visible but olso one will disapear so there will be one unused view. Android wil take that unused view, fill it with new data and use it for newly appeared item. I found some more info here.

这篇关于Android的 - 任何的ListView项目所做的任何更改受到影响的第一个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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