微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – ArrayAdapter显示错误无法解决构造函数适配器错误

我的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);

此外,您还要确保这是指活动上下文

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐