我用的是BaseAdapter:
代码如下:
mBaseAdapter=new BaseAdapter() {
@Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
// TODO Auto-generated method stub
Myholder myHolder;
if(arg1 == null){
myHolder=new Myholder();
arg1=LayoutInflater.from(MainActivity.this).inflate(R.layout.item, null);
myHolder.text_one=(TextView) arg1.findViewById(R.id.tv_title);
myHolder.text_two=(TextView) arg1.findViewById(R.id.tv_content);
arg1.setTag(myHolder);
}else{
myHolder=(Myholder) arg1.getTag();
}
HashMap<String,String> s = list.get(arg0);
Log.i("Tag", " load position : "+arg0+" , title : "+s.get("ItemTitle")+" , text : "+s.get("ItemText")+" , view1 : "+myHolder.text_one+" , view2 : "+myHolder.text_two);
myHolder.text_one.setText(list.get(arg0).get("ItemTitle"));
myHolder.text_two.setText(list.get(arg0).get("ItemText"));
return arg1;
}
这个是getView的代码 ,
但是数据项的log 很诡异 , 当我将listView往下面拖的时候的log:
11-26 16:54:49.596: I/Tag(28093): load position : 17 , title : 第17行标题 , text : 第17行内容 , view1 : android.widget.TextView@4076c1b0 , view2 : android.widget.TextView@4076c930
11-26 16:54:49.626: I/Tag(28093): load position : 18 , title : 第18行标题 , text : 第18行内容 , view1 : android.widget.TextView@4076c1b0 , view2 : android.widget.TextView@4076c930
11-26 16:54:49.896: I/Tag(28093): load position : 19 , title : 第19行标题 , text : 第19行内容 , view1 : android.widget.TextView@4076c1b0 , view2 : android.widget.TextView@4076c930
11-26 16:54:50.497: I/Tag(28093): load position : 20 , title : 第20行标题 , text : 第20行内容 , view1 : android.widget.TextView@4076c1b0 , view2 : android.widget.TextView@4076c930
11-26 16:54:50.967: I/Tag(28093): load position : 21 , title : 第21行标题 , text : 第21行内容 , view1 : android.widget.TextView@4076c1b0 , view2 : android.widget.TextView@4076c930
11-26 16:54:51.658: I/Tag(28093): load position : 22 , title : 第22行标题 , text : 第22行内容 , view1 : android.widget.TextView@4076c1b0 , view2 : android.widget.TextView@4076c930
11-26 16:54:52.078: I/Tag(28093): load position : 23 , title : 第23行标题 , text : 第23行内容 , view1 : android.widget.TextView@4076c1b0 , view2 : android.widget.TextView@4076c930
11-26 16:54:54.521: I/Tag(28093): load position : 24 , title : 第24行标题 , text : 第24行内容 , view1 : android.widget.TextView@4076c1b0 , view2 : android.widget.TextView@4076c930
11-26 16:54:56.382: I/Tag(28093): load position : 25 , title : 第25行标题 , text : 第25行内容 , view1 : android.widget.TextView@4076c1b0 , view2 : android.widget.TextView@4076c930
11-26 16:54:57.413: I/Tag(28093): load position : 26 , title : 第26行标题 , text : 第26行内容 , view1 : android.widget.TextView@4076c1b0 , view2 : android.widget.TextView@4076c930
11-26 16:55:01.698: I/Tag(28093): load position : 27 , title : 第27行标题 , text : 第27行内容 , view1 : android.widget.TextView@4076c1b0 , view2 : android.widget.TextView@4076c930
11-26 16:55:02.879: I/Tag(28093): load position : 28 , title : 第28行标题 , text : 第28行内容 , view1 : android.widget.TextView@4076c1b0 , view2 : android.widget.TextView@4076c930