這問題 困擾了我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;
}
}
檢查一下你這個activity綁定的layout裡面有id為LV_store的listView,,從報錯來看的話,可能是這個listView的問題.
另外,建議id的話不要用大寫的字母