我正在尝试创建一个显示RecyclerView中的订单列表的应用程序。 每个订单都有自己的工具栏(附有操作栏),但每当我启动该活动时,前2个订单都不会将操作栏附加到工具栏... 以下是我的一些代码片段:
onBindViewHolder cod -
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
// - get element from your dataset at this position
// - replace the contents of the view with that element
String customer_name=mDataset[position].getCustomer().getFirstName()+" "+mDataset[position].getCustomer().getLastName();
String customer_phone=mDataset[position].getCustomer().getPhone()+"";
//Dates
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
//
String date=sdf.format(mDataset[position].getBookingDate() );
String booking_date="Booking Date\n"+date;
//
date=sdf.format(mDataset[position].getPickUpDate());
String pickup_date="Pick Up Date\n"+date;
//
date=sdf.format(mDataset[position].getDropDate());
String drop_date="Drop Date\n"+date;
holder.order_id_oh.setText(mDataset[position].getOrderCode());
holder.booking_date_oh.setText(booking_date);
holder.pickup_date_oh.setText(pickup_date);
holder.order_status_oh.setText(mDataset[position].getStatus().toString());
holder.drop_date_oh.setText(drop_date);
holder.customer_name_oh.setText(customer_name);
holder.phone_no_oh.setText(customer_phone);
holder.pickup_locaion_oh.setText(mDataset[position].getAddress());
holder.drop_location_oh.setText(mDataset[position].getCustomer().getAddress());
//
//
((AppCompatActivity)orderAdapter_ctx).setSupportActionBar(holder.menu_toolbar_oh);
//
holder.phone_no_oh.setTextColor(Color.parseColor("#845a9a"));
//
}
获取Context的参数化构造函数 -
public OrderAdapter(Order[] myDataset,Context ctx) {
orderAdapter_ctx=ctx;
mDataset = myDataset;
}
与Recycler相关的部分活动 -
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_order_history);
//
mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view_order_history);
// use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
mRecyclerView.setHasFixedSize(true);
// use a linear layout manager
mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);
mAdapter = new OrderAdapter(orders,this);
mRecyclerView.setAdapter(mAdapter);
以下是2个屏幕截图:
First 2 Orders don't have the actionbar attached (3 dots are missing)
Here the actionbar is attached (3 dots are present)
请帮帮我...