以下是日志记录, 此记录将显示与itemView的数量相同的次数。 但我的应用程序仍在正常运行。
D/ViewGroup﹕ addInArray been called, this = android.support.v7.widget.RecyclerView{44dd4fc8 VFEDID 0,86-720,1140 7f0e01cc app:id/order_query_rv}call stack =
java.lang.Throwable: addInArray
at android.view.ViewGroup.addInArray(ViewGroup.java:3788)
at android.view.ViewGroup.addViewInner(ViewGroup.java:3742)
at android.view.ViewGroup.addView(ViewGroup.java:3566)
at android.view.ViewGroup.addView(ViewGroup.java:3511)
at android.support.v7.widget.RecyclerView$4.addView(RecyclerView.java:538)
at android.support.v7.widget.ChildHelper.addView(ChildHelper.java:83)
at android.support.v7.widget.RecyclerView$LayoutManager.addViewInt(RecyclerView.java:6025)
at android.support.v7.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:5983)
at android.support.v7.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:5971)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1373)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1322)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:556)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2673)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:2971)
at android.view.View.layout(View.java:15302)
at android.view.ViewGroup.layout(ViewGroup.java:4864)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1888)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1742)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1651)
at android.view.View.layout(View.java:15302)
at android.view.ViewGroup.layout(ViewGroup.java:4864)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1888)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1742)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1651)
at android.view.View.layout(View.java:15302)
at android.view.ViewGroup.layout(ViewGroup.java:4864)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1160)
at android.view.View.layout(View.java:15302)
at android.view.ViewGroup.layout(ViewGroup.java:4864)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:515)
at android.widget.FrameLayout.onLayout(FrameLayout.java:450)
at android.view.View.layout(View.java:15302)
at android.view.ViewGroup.layout(ViewGroup.java:4864)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1888)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1742)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1651)
at android.view.View.layout(View.java:15302)
at android.view.ViewGroup.layout(ViewGroup.java:4864)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:515)
at android.widget.FrameLayout.onLayout(FrameLayout.java:450)
at android.view.View.layout(View.java:15302)
at android.view.ViewGroup.layout(ViewGroup.java:4864)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2323)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2029)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1192)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6231)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:817)
at android.view.Choreographer.doCallbacks(Choreographer.java:619)
at android.view.Choreographer.doFrame(Choreographer.java:588)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:803)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5409)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit MethodAndArgsCaller.run(ZygoteInit.java:859)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:675)
at dalvik.system.NativeStart.main(Native Method)
我已经搜索了很长时间,仍然找不到解决这个问题的方法。是什么导致了这个Throwable错误,该如何解决它。
活动
public class OrderQueryActivity extends BaseActivity implements IOrderQueryView {
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.base_mains);
super.onCreate(savedInstanceState);
dealTopMenu();
this.iPresenter = new OrderQueryPresenter(OrderQueryActivity.this, new OrderQueryDao());
}
@Override
public void initView() {
super.initView();
final View contentView = View.inflate(getContext(), R.layout.layout_online_order_query, null);
this.orderQueryTitle = (LinearLayout) contentView.findViewById(R.id.order_query_title_ll);
this.addView(contentView);
this.sumNum = (TextView) contentView.findViewById(R.id.order_num_tv);
this.sumWeigh = (TextView) contentView.findViewById(R.id.order_weight);
this.sumAmount = (TextView) contentView.findViewById(R.id.order_total_amount);
this.rv = (RecyclerView) contentView.findViewById(R.id.order_query_recycler_view);
this.rv.setHasFixedSize(true);
this.rv.setLayoutManager(new LinearLayoutManager(getContext()));
}
@Override
public void setAdapterForRv() {
this.adapter = new OrderQueryAdapter(iPresenter);
this.rv.setAdapter(adapter);
}
}
xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/order_query_title_ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/gray"
android:orientation="vertical"
android:visibility="invisible">
<TextView
style="@style/online_order_query_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="4dp"
android:paddingTop="4dp"
android:text="@string/total_order_num" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:orientation="horizontal"
android:paddingLeft="72dp">
<TextView
android:id="@+id/order_num_tv"
style="@style/online_order_query_title_bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/order_number_example" />
<TextView
style="@style/online_order_query_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/order_number_unit" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="horizontal">
<TextView
android:id="@+id/order_weight"
style="@style/online_order_query_title_bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/order_weight_example" />
<TextView
style="@style/online_order_query_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/weight_unit" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="horizontal">
<TextView
android:id="@+id/order_total_amount"
style="@style/online_order_query_title_bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/order_total_amount_example" />
<TextView
style="@style/online_order_query_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="4dp"
android:text="@string/money_unit" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/order_query_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
</LinearLayout>
适配器
public class OrderQueryAdapter extends RecyclerView.Adapter<OrderQueryAdapter.ViewHolder> {
private ArrayList<OrderBean> orderData;
private IOrderQueryPresenter presenter;
public OrderQueryAdapter(IOrderQueryPresenter presenter) {
this.presenter = presenter;
this.orderData = presenter.getOrderData();
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.query_online_order_card_item, parent, false);
return new ViewHolder(v);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
OrderBean order = orderData.get(position);
holder.dealerName.setText(order.getChannelName());
holder.orderTime.setText(order.getOrderTime());
holder.orderStatus.setText(order.getOrderStatus());
holder.prodsNum.setText(order.getOrderSumNumber());
holder.prodsWeight.setText(order.getWeight());
holder.orderAmount.setText(order.getOrderSumPrice());
holder.payment.setText(order.getPayAmount());
OnDetailClickListener onDetailClickListener = new OnDetailClickListener(presenter, position);
holder.orderContentll.setOnClickListener(onDetailClickListener);
}
@Override
public int getItemCount() {
return orderData.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
TextView dealerName, orderTime, orderStatus, prodsNum, prodsWeight, orderAmount, payment;
LinearLayout orderContentll;
public ViewHolder(View view) {
super(view);
this.dealerName = (TextView) view.findViewById(R.id.dealer_name);
this.orderTime = (TextView) view.findViewById(R.id.order_time);
this.orderStatus = (TextView) view.findViewById(R.id.order_status);
this.prodsNum = (TextView) view.findViewById(R.id.prod_count_online_order);
this.prodsWeight = (TextView) view.findViewById(R.id.prod_weight_online_order);
this.orderAmount = (TextView) view.findViewById(R.id.prod_amount_online_order);
this.payment = (TextView) view.findViewById(R.id.payment_order_online);
this.orderContentll = (LinearLayout) view.findViewById(R.id.ll_order_content);
}
}
static class OnDetailClickListener implements View.OnClickListener {
private int position;
private IOrderQueryPresenter presenter;
public OnDetailClickListener(IOrderQueryPresenter presenter, int position) {
this.presenter = presenter;
this.position = position;
}
@Override
public void onClick(View v) {
int id = v.getId();
switch (id) {
case R.id.ll_order_content:
presenter.startOrderDetail(position);
break;
}
}
}
}
项目XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="2dp">
<android.support.v7.widget.CardView
android:id="@+id/online_pay_card_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="8dp">
<LinearLayout
android:id="@+id/ll_dealer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:orientation="horizontal">
<TextView
android:id="@+id/dealer_name"
style="@style/online_order_query_primary_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/dealer_name" />
<TextView
android:id="@+id/order_time"
style="@style/online_order_query_primary_tv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:text="@string/order_time_example" />
</LinearLayout>
<ImageView
android:id="@+id/divider_one"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@+id/ll_dealer"
android:background="@drawable/single_divider_line_black"
android:contentDescription="@string/app_name" />
<LinearLayout
android:id="@+id/ll_order_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/divider_one"
android:background="@drawable/order_detail_selector"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:orientation="horizontal">
<TextView
style="@style/size14GreyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/order_status_str" />
<TextView
android:id="@+id/order_status"
style="@style/size14GreyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="4dp"
android:text="@string/order_status_example" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:baselineAligned="false"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="left"
android:orientation="horizontal">
<TextView
style="@style/size14GreyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/prod_num_str" />
<TextView
android:id="@+id/prod_count_online_order"
style="@style/size14GreyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="4dp"
android:text="@string/prod_num_example" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="horizontal">
<TextView
style="@style/size14GreyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/prod_weight" />
<TextView
android:id="@+id/prod_weight_online_order"
style="@style/size14GreyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="4dp"
android:text="@string/weight_example" />
<TextView
style="@style/size14GreyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/weight_unit" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="left"
android:orientation="horizontal">
<TextView
style="@style/size14GreyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/order_amount" />
<TextView
android:id="@+id/prod_amount_online_order"
style="@style/online_order_query_primary_tv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="4dp"
android:text="@string/order_amount_example" />
<TextView
style="@style/size14GreyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/money_unit" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<ImageView
android:id="@+id/divider_two"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@+id/ll_order_content"
android:background="@drawable/single_divider_line_black"
android:contentDescription="@string/app_name" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/divider_two"
android:layout_margin="4dp"
android:baselineAligned="false"
android:gravity="center_vertical"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:gravity="left"
android:orientation="horizontal">
<TextView
style="@style/size14GreyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/already_payment" />
<TextView
android:id="@+id/payment_order_online"
style="@style/online_order_query_primary_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="4dp"
android:text="@string/order_payment_example" />
<TextView
style="@style/size14GreyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/money_unit" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:orientation="horizontal">
<Button
android:id="@+id/payment_detail_btn"
style="@style/iBtn_listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/mm_title_btn_right"
android:paddingLeft="24dp"
android:paddingRight="24dp"
android:text="@string/payment_detail" />
<Button
android:id="@+id/pay_online_order_btn"
style="@style/iBtn_listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:background="@drawable/mm_title_btn_right"
android:paddingLeft="24dp"
android:paddingRight="24dp"
android:text="@string/pay_online_order" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>