baseadapter例子里,listview里所有按钮有重用么

寂寞的地瓜 发布于 2013/08/08 13:27
阅读 151
收藏 0

您好 请教一个baseadapter的问题

您那个baseadapter例子里,listview里所有按钮有重用么?

我按照您的写了,结果是所有按钮的id一样,当按钮的hashcode和convertView一样有重用,这是为什么呢?

 

 

 

加载中
0
贺路的路
贺路的路
是不是把id写成position了,没上代码啊
0
寂寞的地瓜

没有啊  ,下面是BaseAdapter


public class MyAdapter extends BaseAdapter{



private LayoutInflater mInflater;

public MyAdapter(Context context){
this.mInflater = LayoutInflater.from(context);
}

@Override
public int getCount() {
// TODO Auto-generated method stub
return getDate().size();
}


@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}


@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}


@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
Log.v("MyLisViewBaset", "getView " + position + "  " + convertView);


if(convertView == null){
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.baseadapter02, null);
holder.title = (TextView) convertView.findViewById(R.id.baseadapter02_ItemTitle);
holder.text = (TextView) convertView.findViewById(R.id.abaseadapter02_ItemText);
holder.bt = (Button) convertView.findViewById(R.id.baseadapter02_ItemButton);

convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}

holder.title.setText(getDate().get(position).get("ItemTitle").toString());
       holder.text.setText(getDate().get(position).get("ItemText").toString());
       holder.bt.setText(position+"");
       
       holder.bt.setOnClickListener(new OnClickListener() {
        @Override
           public void onClick(View v) {
        
        System.out.println("dfdfdfdfdfdf");
           Log.v("=======================================", "==========================================");
            Log.v("MyListViewBase", "你点击了按钮" + position);
           Log.v("MyListViewBase", "你点击了按钮" + v.toString() + "  id:" + v.getId()); 
           }
       });
return convertView;
}


public final class ViewHolder{
public TextView title;
public TextView text;
public Button bt;
}
}