我创建了一个自定义列表适配器来显示列表视图中的项目。但是这个列表适配器在某些设备中不起作用。当我尝试记录数据是否到达适配器时,它到达那里。 Folowing是我的列表适配器的代码。 请帮忙:
public class CustomListAdapter extends BaseAdapter {
private Activity activity;
private LayoutInflater inflater;
private List<Schedule> ScheduleItems;
public CustomListAdapter(Activity activity, List<Schedule> ScheduleItems) {
this.activity = activity;
this.ScheduleItems = ScheduleItems;
}
@Override
public int getCount() {
return ScheduleItems.size();
}
@Override
public Object getItem(int location) {
return ScheduleItems.get(location);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolderItem viewHolder;
if(convertView==null){
// inflate the layout
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.listvehtemplate, null);
// well set up the ViewHolder
viewHolder = new ViewHolderItem();
// viewHolder.status= (ImageView) convertView.findViewById(R.id.cusid);
viewHolder.textViewName=(TextView) convertView.findViewById(R.id.cusname);
// viewHolder.textViewAddress=(TextView) convertView.findViewById(R.id.cusdesc);
//
convertView.setTag(viewHolder);
}else{
// we've just avoided calling findViewById() on resource everytime
// just use the viewHolder
viewHolder = (ViewHolderItem) convertView.getTag();
}
// getting Schedule data for the row
Schedule m = ScheduleItems.get(position);
if(m != null) {
viewHolder.textViewName.setText(String.valueOf(m.getcustomername()));
Log.d("log",viewHolder.textViewName.getText().toString());
if(m.getcusid().equals("Finished")){
viewHolder.textViewName.setTextColor(Color.GREEN);
}
else{
viewHolder.textViewName.setTextColor(Color.RED);
// viewHolder.status.setImageResource(R.drawable.xmark);
}
// viewHolder.textViewAddress.setText(String.valueOf(m.getcustomeraddress()));
}
return convertView;
}
static class ViewHolderItem {
// ImageView status;
TextView textViewName;
// TextView textViewAddress;
}
}