我想从列表视图
中删除该项目我的代码用于listview
this.lv1.setAdapter(new ArrayAdapter<String>(FindFilesByType.this, android.R.layout.test_list_item,Ringtones));
// setListAdapter(new ArrayAdapter<String>(FindFilesByType.this, R.layout.main,
// Ringtones));
//
this.lv1.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> aView, View v,
int position, long id) {
currentPosition = position;
playRingtone(DIRECTORY+Ringtones.get(position));
Toast.makeText(FindFilesByType.this, "postion "+DIRECTORY+Ringtones.get(position), Toast.LENGTH_LONG).show();
GlobalVariable.SetstrEmail(DIRECTORY+Ringtones.get(position));
GlobalVariable.SetcurrentPosition(position);
}
});
现在如何从中删除所选项目?
答案 0 :(得分:1)
答案 1 :(得分:1)
我在我的代码中使用了这样的东西,它可以删除列表中的多个项目
ListView lv_ArchivePartylist;
ArrayList<Parties> select_archived_party;
lv_ArchivePartylist = (ListView)findViewById(R.id.archive_ListView01);
lv_ArchivePartylist.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,long id) {
// TODO Auto-generated method stub
if(view.findViewById(R.id.img_chkbox_archive).getVisibility()==TextView.GONE)
{
view.findViewById(R.id.img_chkbox_archive).setVisibility(TextView.VISIBLE);
Toast.makeText(ctx_archive, "Name="+archived_parties.get(position).getPartyTitle(), Toast.LENGTH_SHORT).show();
select_archived_party.add(archived_parties.get(position));
}
}
});
然后我宣布了一个“删除”按钮,在它的On ClickListener方法上,它调用数据库中的代码(在你的情况下,它可能是Arraylist或数组)来删除在Arraylist“select_archived_party”中选择的项目。 希望它有所帮助: - )