想要从列表视图中删除项目并添加到另一个列表视图

时间:2016-01-13 10:10:23

标签: android listview

列表中删除,但根据位置添加。因此,在列表中添加重复项

refreshedList.remove(new_position);
mg_mappingAdapter2.notifyDataSetChanged();
mgBenData.add(mgBenData.get(new_position));
mg_mappingAdapter.notifyDataSetChanged();
mg_mappingAdapter2 = new MgMappingAdapter2(getActivity(), refreshedList);
mg_mappingAdapter = new MgMappingAdapter11(getActivity(),
    R.layout.mgnregauserlistlayout,mgBenData);
mListView.setAdapter(mg_mappingAdapter);
mappedListView.setAdapter(mg_mappingAdapter2);

1 个答案:

答案 0 :(得分:0)

尝试这种方式:

Object object = refreshedList.remove(new_position); // replace Object with Element type of List, ArrayList<Element>
mgBenData.add(object);
 mg_mappingAdapter2.notifyDataSetChanged();
 mg_mappingAdapter.notifyDataSetChanged();
 mg_mappingAdapter2 = new MgMappingAdapter2(getActivity(), refreshedList);
 mg_mappingAdapter = new MgMappingAdapter11(getActivity(),
R.layout.mgnregauserlistlayout,mgBenData);
     mListView.setAdapter(mg_mappingAdapter);
     mappedListView.setAdapter(mg_mappingAdapter2);

只需在列表中添加已删除的项目即可在列表中显示已删除的项目。希望它能为您提供帮助。