我已经创建了一个方法deleteItem,它必须删除该行,但是在我单击按钮后它会继续存在,如果我再试一次,我会得到一个例外。
public class WITHistory extends WITBase implements OnItemClickListener{
private ListView listView;
public int del;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.history_wit);
listView = (ListView) findViewById(R.id.listSearch);
HistoryAdapter adapter = new HistoryAdapter(this, searches);
listView.setAdapter(adapter);
listView.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int pos,long id) {
Toast.makeText(this, "You selected Row ["+pos+"]\n"+
"For donation data ["+searches.get(pos)+"]\n"+"With ID of ["+id+"]", Toast.LENGTH_LONG).show();
del = pos;
}
public void deleteItem(View v) {
searches.remove(del);
}
}
答案 0 :(得分:0)
将您的适配器声明为类成员
并添加
public void deleteItem(View v) {
searches.remove(del);
adapter.notifyDataSetChanged ().;
}