English 中文(简体)
不得删除清单 清单中的项目
原标题:Not Able to delete listItem from ListView Android

我正在使用这一法典来这样做,但现在该法典并没有发挥作用。 我可以选择检查箱,当我点击 but子时,没有发生。

SimpleAdapter adapter;
List<HashMap<String, String>> painItems = new ArrayList<HashMap<String, String>>();
ListView listthings;
   ...

    cb = (CheckBox)findViewById(R.id.checkBox1);    
    adapter = new SimpleAdapter(this, painItems, R.layout.mylistlayout,
            from, to);
    listthings.setAdapter(adapter);
    listthings.setOnItemClickListener(this);

    deleteButton = (Button) findViewById(R.id.deleteButton);
    deleteButton.setOnClickListener(this);

 ...

public void onClick(View v) {

    if (v == this.deleteButton) {
//      Toast.makeText(this, "delete clicked", Toast.LENGTH_SHORT).show();
        deleteCheckedItems();
    }
}

...
 private void deleteCheckedItems() {
    int count = this.listthings.getAdapter().getCount();
    for (int i = 0; i < count; i++) {
        if (this.listthings.isItemChecked(i)) {
            painItems.remove(i);
            adapter.notifyDataSetChanged();
                            listthings.invalidateViews();
        }
    }

感谢任何帮助。 感谢 你提前。

最佳回答

(1) 不是调适者。

2) Why did you use: listthings.invalidateViews(); ? You can remove this line, this will redraw your list

3) why havn t you accepted my answer here: How to implement check box in listView Android to delete listItems

4) have you tested a toast after painItems.remove(i); that will show you if items are really removed? Or maybe just after calling deleteCheckedItems(), display the new painItems to see if everything worked

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签