为什么Listview在返回单击时重复最后一个条目??????第一次使用ListView启动该类时,它显示的所有数据都是正确的,现在我单击一个列表项并再次从描述中按回,然后它重复最后一个条目。
例如
ListItems 是:A -> B -> C
现在我单击 B 并转到下一页,然后单击返回,然后列表是:
A -> B -> C -> C
当我再次按 A 并从该 A 描述页面中单击返回时,列表为:
A -> B -> C -> C -> C
为什么它重复最后一个条目????
活动类代码如下:
if(list.isEmpty())
{
if(adapter==null)
{
adapter=new MyAdapter(context, list);
ls.setAdapter(adapter);
}
adapter.notifyDataSetChanged();
}
@Override
protected void onStop() {
super.onStop();
AppointmentListView.setVisibility(View.GONE);
}
@Override
protected void onRestart() {
super.onRestart();
AppointmentListView.setVisibility(View.VISIBLE);
}
MyAdapter 类是:
public class MyAdapter extends BaseAdapter{
public ArrayList<HashMap<String,String>> list;
Context context;
private LayoutInflater mInflater;
String appointType;
public MyAdapter(Context context, ArrayList<HashMap<String,String>> list)
{
super();
this.context=context;
this.list = list;
mInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
@Override
public int getViewTypeCount()
{
return 1;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return list.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
static class ViewHolder {
TextView AppTime_List;
TextView CustomerName_List;
TextView CustomerAddress_List;
TextView AppID_List;
Button MapButton;
}
// @Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder;
if (convertView == null)
{
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.listviewsample, parent, false);
holder.AppTime_List = (TextView) convertView.findViewById(R.id.time);
holder.CustomerName_List = (TextView) convertView.findViewById(R.id.name);
holder.CustomerAddress_List = (TextView) convertView.findViewById(R.id.Address);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
appointType=(String)list.get(position).get("Name");
holder.AppID_List.setText((String)list.get(position).get("ID"));
holder.AppTime_List.setText((String)list.get(position).get("Time"));
holder.CustomerName_List.setText((String)list.get(position).get("Name"));
holder.CustomerAddress_List.setText((String)list.get(position).get("Address"));
return convertView;
}
}
有人可以帮我吗?