Reputation: 6888
I have written code to delete Image from SD Card, and my code just works fine, what if i want to delete whole row, not just image.
actually each and every row of List View contains, a image with two buttons, so whenever i do tap on remove button, it is just removing image not deleting that particular row.
final ImageButton btnDelete = (ImageButton) convertView.findViewById(R.id.btnDelete);
btnDelete.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
fileName = ImageList.get(position).toString().substring(strPath.lastIndexOf('/')+1, strPath.length());
String fileToDelete = Environment.getExternalStorageDirectory().getPath() + fileName;
Log.d("FileToDelete", fileToDelete);
File myFile = new File(fileToDelete);
if(myFile.exists())
myFile.delete();
((BaseAdapter) lstView.getAdapter()).notifyDataSetChanged();
}
});
getView(...)
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
// If this item is to be synced
if(flags.get(position)) {
startUpload(position);
// Mark as synced
flags.put(position, false);
}
Upvotes: 0
Views: 97
Reputation: 5068
you need to get view that you are binding to that listview. you can get that view using position variable. and delete like
myList.remove(position);
and then call adapter.notifyDataSetChanged();
Upvotes: 2