Android ListView上一项重复上一次单击
为什么Listview在返回时重复最后一个条目单击?????第一次使用Listview启动该类时,它显示的所有数据都是正确的,现在我单击其中一个列表项,然后再次按“说明”中的“返回”,然后它重复最后一个条目 e、 g 清单项目包括: A->B->C 现在我点击B,进入下一页,然后点击后退,列表如下: A->B->C->C 再次,当我按下A键并从该描述页面中单击“上一步”时,列表为: A->B->C->C->C 为什么重复最后一个条目 活动类别代码如下所示:Android ListView上一项重复上一次单击,android,android-listview,baseadapter,Android,Android Listview,Baseadapter,为什么Listview在返回时重复最后一个条目单击?????第一次使用Listview启动该类时,它显示的所有数据都是正确的,现在我单击其中一个列表项,然后再次按“说明”中的“返回”,然后它重复最后一个条目 e、 g 清单项目包括: A->B->C 现在我点击B,进入下一页,然后点击后退,列表如下: A->B->C->C 再次,当我按下A键并从该描述页面中单击“上一步”时,列表为: A->B->C->C->C 为什么重复最后一个条目 活动类别代码如下所示: if(list.is
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;
}
}
公共类MyAdapter扩展了BaseAdapter{
公共阵列列表;
语境;
私人停车场;
字符串指定类型;
公共MyAdapter(上下文、ArrayList列表)
{
超级();
this.context=context;
this.list=列表;
mInflater=LayoutInflater.from(上下文);
}
@凌驾
public int getCount(){
//TODO自动生成的方法存根
返回list.size();
}
@凌驾
public int getViewTypeCount()
{
返回1;
}
@凌驾
公共对象getItem(int位置){
//TODO自动生成的方法存根
返回列表。获取(位置);
}
@凌驾
公共长getItemId(int位置){
//TODO自动生成的方法存根
返回位置;
}
静态类视图持有者{
TextView应用程序时间列表;
TextView客户名称列表;
TextView客户地址列表;
TextView应用程序ID_列表;
按钮映射按钮;
}
//@覆盖
公共视图getView(int位置、视图转换视图、视图组父视图){
//TODO自动生成的方法存根
视窗座;
if(convertView==null)
{
holder=新的ViewHolder();
convertView=mInflater.inflate(R.layout.listviewsample,父项,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=(ViewHolder)convertView.getTag();
}
appointType=(字符串)list.get(位置).get(“名称”);
holder.AppID_List.setText((String)List.get(position.get(“ID”));
holder.AppTime_List.setText((字符串)List.get(位置).get(“时间”);
holder.CustomerName_List.setText((字符串)List.get(位置).get(“名称”);
holder.CustomerAddress_List.setText((字符串)List.get(位置).get(“地址”);
返回视图;
}
}
有人能帮我吗???这里的问题是MyAdapter getCount方法。现在在MyAdapter类中,我在顶部声明了列表大小:
int list_size;
public MyAdapter(Context context, ArrayList<HashMap<String,String>> list)
{
super();
this.context=context;
this.list = list;
mInflater = LayoutInflater.from(context);
list_size=list.size();
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return list_size();
}
int-list\u-size;
公共MyAdapter(上下文、ArrayList列表)
{
超级();
this.context=context;
this.list=列表;
mInflater=LayoutInflater.from(上下文);
list_size=list.size();
}
@凌驾
public int getCount(){
//TODO自动生成的方法存根
返回列表_size();
}
您能同时提供活动代码吗……。请检查我更新的问题您能提供部分代码来填写列表中的元素吗?它位于顶部,请检查我的问题:活动代码