I have a list view with implement on click element
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);
}
}
}
});
After the element has been tapped I am adding to the list and changing the icon on the list view.
I can choose multiple elements at one time. Everything is working is working perfectly until I delete some of the elements.
Code of the method
@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();
}
The method is removing the element from the list view, but the problem is that removed element (let say index two) has element under index three then element there will be element two after deletion. Element number two had another icon set as element three, but after deletion old element three is getting "selected icon" of old element two.
This is how it looks in practice.
Before deleting
After deleting
Does anyone have an idea how I can reset the image views of all other elements after deletion of one of them?