我的ArrayAdapter显示无法解析适配器.请让我知道语法有什么问题.
@Override
public void onRequestSuccess(List<Order> Items) {
Toast.makeText(HomeActivity.this, "Success", Toast.LENGTH_SHORT).show();
List<Order> list = new ArrayList<Order>();
ListView listView = (ListView) findViewById(R.id.listview);
listadapter<Order> adapter = new listadapter<String>(this, android.R.layout.simple_list_item_1, list);
listView.setAdapter(adapter);
}
MY Order类看起来像这样.
public class Order {
public String createdOn;
public String id;
public String lastModifiedOn;
public String trackingNumber;
public String tripId;
public OrderEntry orderEntry;
public String tripOrderStatusValue;
public String notificationStatus;
public String remark;
public String createdBy;
public String orderId;
public String deliveryReasonCode;
public Boolean isTripStarted;
public Boolean isTripCompleted;
public Boolean isOutScanned;
public String shipmentType;
public String deliveryTime;
}
我的listadapter看起来像这样.
公共类listadapter扩展ArrayAdapter {
public listadapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
// Todo Auto-generated constructor stub
}
private List<Order> items;
public listadapter(Context context, int resource, List<Order> items) {
super(context, resource, items);
this.items = items;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi;
vi = LayoutInflater.from(getContext());
v = vi.inflate(R.layout.list_row_myschedule, null);
}
Order p = items.get(position);
if (p != null) {
TextView tt = (TextView) v.findViewById(R.id.textview1);
TextView tt1 = (TextView) v.findViewById(R.id.textview2);
TextView tt3 = (TextView) v.findViewById(R.id.textview3);
if (tt != null) {
tt.setText(p.orderStatusValue);
}
if (tt1 != null) {
tt1.setText(p.reasonCode);
}
if (tt3 != null) {
tt3.setText(p.trackingNumber);
}
}
return v;
}
}
解决方法:
泛型必须在声明/初始化中保持一致
更改
ArrayAdapter<Order> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list);
同
ArrayAdapter<Order> adapter = new ArrayAdapter<Order>(this, android.R.layout.simple_list_item_1, list);
此外,您还要确保这是指活动上下文