我在显示自定义列表时遇到问题我检查了数组,它不是空的,但列表仍然没有显示:
适配器类:
public class ReportAdapter extends BaseAdapter{
private Context context;
Report data[] = null;
public ReportAdapter(Context context, Report[] d) {
data = d;
this.context = context;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row=convertView;
if(convertView == null){
LayoutInflater inf = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
row = inf.inflate(R.layout.list_row, null);
}
ImageView imageUrl = (ImageView)row.findViewById(R.id.imageUrl);
TextView reportName = (TextView)row.findViewById(R.id.reportName);
TextView reportState = (TextView)row.findViewById(R.id.reportState);
TextView reportTime = (TextView)row.findViewById(R.id.reportTime);
//Report report = data[position];
imageUrl.setImageDrawable(data[position].Image);
reportName.setText(data[position].Name);
reportState.setText(data[position].State);
reportTime.setText(data[position].Time);
return row;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return 0;
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
}
报告类:
public class Report {
public String Name;
public String Time;
public Drawable Image;
public String State;
public Report(){
super();
}
public Report(String Name, String Time,Drawable Image,String State) {
super();
this.Name = Name;
this.Time = Time;
this.Image = Image;
this.State = State;
}
}
主类:
Report report_data[] = new Report[reports.length()];
//start loop
report_data[i] = new Report(c.getString(TAG_TITLE),c.getString(TAG_TIME),drawable,"Pidding");
// end loop
list = (ListView)findViewById(R.id.list);
ReportAdapter adapter = new ReportAdapter(Display_Reports.this,report_data);
list.setAdapter(adapter);
我确定代码是正确的,但是我还没有发现一个小错误。谢谢。