Reputation: 1686
I have a button and when I click it I want to delete the value of arraylist first index, and yes the first index in the array list is deleted. But the data in my listview that came from my arraylist is not deleted.
Here I got so far
public ArrayList<String> imagesFileName = new ArrayList<String>();
mylist = new ArrayList<HashMap<String, String>>();
for (int i = 0; i < imagesFileName.size(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
map.put(FILE_NAME, filename[i]);
map.put(DESCRIPTION, "desc");
map.put(UPLOADEDBY, "uploadby");
map.put(DATE_UPLOAD, "date_upload");
map.put(ACTION, "delete");
map.put(ID, String.valueOf(i));
mylist.add(map);
}
adapter = new CustomArrayAdapter(getApplicationContext(), mylist, R.layout.attribute_ireport_list,
new String[]{FILE_NAME, DESCRIPTION, UPLOADEDBY, DATE_UPLOAD, ACTION, ID},
new int[]{R.id.tv_File, R.id.txt_Desc, R.id.tv_UploadedBy, R.id.tv_DateUploaded, R.id.tv_Action, R.id.txt_id}, true);
lv_iReport.setAdapter(adapter);
//code for delete of first index
btn_Upload = (Button) findViewById(R.id.button1);
btn_Upload.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
imagesFileName.remove(0);
adapter = new CustomArrayAdapter(getApplicationContext(), mylist, R.layout.attribute_ireport_list,
new String[]{FILE_NAME, DESCRIPTION, UPLOADEDBY, DATE_UPLOAD, ACTION, ID},
new int[]{R.id.tv_File, R.id.txt_Desc, R.id.tv_UploadedBy, R.id.tv_DateUploaded, R.id.tv_Action, R.id.txt_id}, true);
lv_iReport.setAdapter(adapter);
Toast.makeText(getApplicationContext(), "Deleted", Toast.LENGTH_LONG).show();
}
});
Upvotes: 1
Views: 478
Reputation: 501
try this:
btn_Upload.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
mylist.remove(0);
adapter.notifyDataSetInvalidated();
}
});
Upvotes: 2
Reputation: 2671
Simply use that :
myList.remove(object);
notifyDataSetChanged();
Upvotes: 0