0
我有掣子元件的Android - 修改列表視圖元素刪除另一個元素
mProfiles.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
fileName=profileListViewAdapter.getItem(position).getRawName();
if(!selectionMode) {
profileParser.parseProfile(getApplicationContext(), fileName, true);
profileSelected();
}
else {
if(!selectedProfiles.contains(new SelectedProfilesDataModel(fileName,position))) {
selectedProfiles.add(new SelectedProfilesDataModel(fileName,position));
ImageView imageView=(ImageView)view.findViewById(R.id.imageViewHouseProfile);
imageView.setImageResource(R.drawable.picked);
}
else {
selectedProfiles.remove(new SelectedProfilesDataModel(fileName,position));
ImageView imageView=(ImageView)view.findViewById(R.id.imageViewHouseProfile);
imageView.setImageResource(R.mipmap.house_icon);
}
}
}
});
上實現的列表視圖元素被竊聽了我添加到列表和列表視圖改變圖標後後。
我可以一次選擇多個元素。 一切工作正常,直到我刪除了一些元素。
方法
@OnClick(R.id.buttonDeleteProfile)
public void deleteProfile(){
selectionMode =false;
for(SelectedProfilesDataModel spdm:selectedProfiles) {
File file = new File(getFilesDir(), spdm.getName());
profileParser.deleteProfile(file);
}
profileListViewAdapter.clear();
fileProfiles = profileParser.listProfilesFiles(getApplicationContext());
profileListViewAdapter.setData(fileProfiles);
profileListViewAdapter.notifyDataSetChanged();
}
的方法除去從列表視圖的元件,但問題是,除去的元件(比方說指數爲兩個)的碼具有下指數三元然後元件會有元件兩個刪除後。元素二將另一個圖標設置爲元素三,但刪除後舊元素三正在獲取舊元素二的「選定圖標」。
這是它在實踐中的樣子。
之前刪除
刪除
有沒有人有一個想法,我可以怎麼他們中的一個刪除後重新設置所有其他元素的形象意見後?