我的回收站视图中有 2 个微调器。现在我的第二个微调器值取决于第一个微调器选定的项目。
我能够在微调器 1 中绑定数据,但是当我尝试基于微调器 1 的 setOnItemSelectedListener 绑定微调器 2 数据时,它只会绑定屏幕上的可见项目。
我想绑定微调器 2 数据,即使它在屏幕上不可见。我有以下适配器代码:
public class CustomerAdapter extends RecyclerView.Adapter<CustomerAdapter.CardViewHolder> {
private ArrayList<MainDetails> mMainDetails;
private Context mContext;
public CustomerAdapter(Context mcontext, ArrayList<MainDetails> mainDetails) {
mContext = mcontext;
mMainDetails = mainDetails;
}
private Context getContext() {
return mContext;
}
@Override
public CardViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
Context context = viewGroup.getContext();
View itemView = LayoutInflater.from(context).inflate(R.layout.row_bind_data, viewGroup, false);
return new CardViewHolder(itemView);
}
@Override
public void onBindViewHolder(final CardViewHolder cardViewHolder, int position) {
final MainDetails testMainDetails = mMainDetails.get(position);
ArrayAdapter<Products> spinnerUserAdapter = new ArrayAdapter<Products>(getContext(), R.layout.dropdown_item, testMainDetails.getUsers());
spinnerUserAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
cardViewHolder.spinner1.setAdapter(spinnerUserAdapter);
cardViewHolder.spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
try {
Products pp = (Products) parent.getSelectedItem();
ArrayAdapter<Orders> spinnerPPAdapter = new ArrayAdapter<Orders>(getContext(), R.layout.pc_estimator_dropdown_item, pp.getOrders());
spinnerPPAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
cardViewHolder.spinner2.setAdapter(spinnerPPAdapter);
} catch (Exception e) {
Log.e("error", e.toString());
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
cardViewHolder.spinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
//other operation
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
@Override
public int getItemCount() {
return mMainDetails.size();
}
public static class CardViewHolder extends RecyclerView.ViewHolder {
public Spinner spinner1;
public Spinner spinner2;
public CardViewHolder(View v) {
super(v);
spinner1 = (Spinner) v.findViewById(R.id.spinner1);
spinner2 = (Spinner) v.findViewById(R.id.spinner2);
}
}
}
我的微调器cardViewHolder.spinner1.setOnItemSelectedListener
方法只要求屏幕上的可见项目,但我想绑定所有数据,即使它不可见。