这问题 困扰了我3天了 不知道为什么 求大神指点
上代码
这是onCreate里面的
// 商品 listview
lv_friend=(ListView) findViewById(R.id.LV_store);
adapter=new Myadapter(this, getdatas());
System.out.println("adapter+++++++++++"+adapter);
lv_friend.setAdapter(adapter);
}
private List<GetDataType> getdatas() {
List<GetDataType> list=new ArrayList<GetDataType>();
GetDataType data1=new GetDataType();
data1.setIv_portrait(R.drawable.ic_launcher);
data1.setName("杨幂");
data1.setSignature("喜欢我就来找我啊");
list.add(data1);
GetDataType data2=new GetDataType();
data2.setIv_portrait(R.drawable.ic_launcher);
data2.setName("范冰冰");
data2.setSignature("我在这里等你哦");
list.add(data2);
GetDataType data3=new GetDataType();
data3.setIv_portrait(R.drawable.ic_launcher);
data3.setName("唐嫣");
data3.setSignature("来追我呀,呵呵");
list.add(data3);
GetDataType data4=new GetDataType();
data4.setIv_portrait(R.drawable.ic_launcher);
data4.setName("李小璐");
data4.setSignature("386562,加我好友呀");
list.add(data4);
GetDataType data5=new GetDataType();
data5.setIv_portrait(R.drawable.ic_launcher);
data5.setName("柳岩");
data5.setSignature("帅哥,过来一下");
list.add(data5);
return list;
}
这是Myadapter
package com.android.workapp;
import java.util.List;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class Myadapter extends BaseAdapter{
private List mData;
private Context mcontext;
private int mid;
public Myadapter(Context context,List data){
this.mcontext=context;
this.mData=data;
}
//获取列表列的数量
@Override
public int getCount() {
return mData.size();
}
//根据postion获取item的数据
@Override
public Object getItem(int position) {
return mData.get(position);
}
//获取position对应的id
@Override
public long getItemId(int position) {
return position;
}
//创建item的视图
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view=View.inflate(mcontext, R.layout.saver_tickey_store_item, null);
//获取item对应的数据对象
GetDataType getdata=mData.get(position);
//初始化view
ImageView iv_portrait= (ImageView) view.findViewById(R.id.IV_portrait);
TextView txt_name=(TextView) view.findViewById(R.id.txt_name);
TextView signature=(TextView) view.findViewById(R.id.signature);
//邦定数据到view
iv_portrait.setImageResource(getdata.getIv_portrait());
txt_name.setText(getdata.getName());
signature.setText(getdata.getSignature());
return view;
}
}
GetDataType
package com.android.workapp;
public class GetDataType {
private int iv_portrait;
private String name;
private String signature;
public int getIv_portrait() {
return iv_portrait;
}
public void setIv_portrait(int iv_portrait) {
this.iv_portrait = iv_portrait;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSignature() {
return signature;
}
public void setSignature(String signature) {
this.signature = signature;
}
}