android怎样选中listview中一行进行删除?
声明这个ListvIew
/生成动态数组,加入数据
listItem = new ArrayList<HashMap<String, Object>>();
map = new HashMap<String, Object>();
for(int i=0;i<10;i++)
{
// 后台数据
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("ItemImage", R.drawable.checked);来下
map.put("ItemTitle", "Level ");
map.put("ItemText", "Finished in 1 Min 54 Secs, 70 Moves!");
listItem.add(map);
}
list.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3)
{
删除操作
listItem.remove(position);//选择行的位置
listItemAdapter.notifyDataSetChanged();
list.invalidate();
listview会删除选择的行,重新更新
}
});
/生成动态数组,加入数据
listItem = new ArrayList<HashMap<String, Object>>();
map = new HashMap<String, Object>();
for(int i=0;i<10;i++)
{
// 后台数据
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("ItemImage", R.drawable.checked);来下
map.put("ItemTitle", "Level ");
map.put("ItemText", "Finished in 1 Min 54 Secs, 70 Moves!");
listItem.add(map);
}
list.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3)
{
删除操作
listItem.remove(position);//选择行的位置
listItemAdapter.notifyDataSetChanged();
list.invalidate();
listview会删除选择的行,重新更新
}
});