当我按下按钮两次时,我试图阻止我的列表视图项目附加。我尝试使用 .Clear() 但我不知道将它放在哪里或如何放置,有时它甚至会阻止项目甚至填充或根本不清除项目。
全球的东西:
ArrayAdapter<CharSequence> adapter;
ArrayList<MessageDetails> details;
我的按钮:
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
try
{
//Tried clearing adapter first before code runs but items do not even get displayed
adapter.clear();
adapter.notifyDataSetChanged();
//sendPostData calls refreshListView method
new sendPostData().execute(nric.getText().toString());
}
catch (Exception e)
{
}
}
我的 refreshListView() 方法:
private void refreshListView()
{
adapter = new ArrayAdapter<CharSequence>(getActivity().getApplicationContext(), android.R.layout.simple_list_item_1, items);
myInfoList.setAdapter(adapter);
details = new ArrayList<MessageDetails>();
MessageDetails Detail;
Detail = new MessageDetails();
for (int i =0; i < itemName.size(); i++)
{
float totalprice = itemPrice.get(i) * Quantity.get(i);
Detail = new MessageDetails();
Detail.setitemName(itemName.get(i));
Detail.setItemDescription(description.get(i));
Detail.setitemPrice(String.valueOf(totalprice));
Detail.setQuantity(Quantity.get(i).toString() + " sets");
Detail.setDate(purchaseDate.get(i).toString());
details.add(Detail);
}
myInfoList.setAdapter(new CustomAdapter(details , getActivity()));
}
编辑删除了第一个适配器。
全局项目:
CustomAdapter mCustomAdapter;
刷新列表视图:
private void refreshListView()
{
details = new ArrayList<MessageDetails>();
MessageDetails Detail;
Detail = new MessageDetails();
for (int i =0; i < itemName.size(); i++)
{
float totalprice = itemPrice.get(i) * Quantity.get(i);
Detail = new MessageDetails();
Detail.setitemName(itemName.get(i));
Detail.setItemDescription(description.get(i));
Detail.setitemPrice(String.valueOf(totalprice));
Detail.setQuantity(Quantity.get(i).toString() + " sets");
Detail.setDate(purchaseDate.get(i).toString());
details.add(Detail);
}
mCustomAdapter = new CustomAdapter(details , getActivity());
myInfoList.setAdapter(mCustomAdapter);
}