我有一个按钮,当我点击它时,我想删除arraylist第一个索引的值,是的,删除了数组列表中的第一个索引。但我的列表视图中来自我的arraylist的数据不会被删除 我到目前为止
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();
}
});
答案 0 :(得分:2)
试试这个:
btn_Upload.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
mylist.remove(0);
adapter.notifyDataSetInvalidated();
}
});
答案 1 :(得分:0)
只需使用:
myList.remove(object);
notifyDataSetChanged();