有人有这样的样本吗? 或者可以告诉适配器看起来怎么样? 这是适配器内部的适配器(用于对recyclerView进行充气的适配器,以及用于对recyclerView的每个项目内的MaterialBetterSpinner布局进行充气的适配器) 感谢名单!
答案 0 :(得分:0)
我认为这会给你一些想法......
public class Yearly_day_type_adapter extends RecyclerView.Adapter<Yearly_day_type_adapter.MyViewHolder> {
private List<Year_Day_Type_Model> moviesList;
private Context context;
TextView txt;
int pos;
private List<String> monthList;
ArrayAdapter<String> monthAdapter;
public class MyViewHolder extends RecyclerView.ViewHolder {
public Spinner spinner_left_yearly;
public MyViewHolder(View view) {
super(view);
spinner_left_yearly = (Spinner) view.findViewById(R.id.spinner_left_yearly);
}
}
public Yearly_day_type_adapter(Context context,List<Year_Day_Type_Model> moviesList) {
this.moviesList = moviesList;
this.context=context;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.yearly_day_type, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(final MyViewHolder holder, final int position) {
populateSpinner();
holder.spinner_left_yearly.setAdapter(monthAdapter);
holder.spinner_left_yearly.setSelection(Integer.parseInt(moviesList.get(position).getMonPos()));
holder.spinner_left_yearly.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
moviesList.get(position).setMonPos(String.valueOf(pos));
MultipleSelectionActivity.setYearlyDayTypeMonth(position,pos);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
@Override
public int getItemCount() {
return moviesList.size();
}
public void populateSpinner() {
monthList = new ArrayList<>();
monthList.add("Januvary");
monthList.add("Februvary");
monthList.add("March");
monthList.add("April");
monthList.add("May");
monthList.add("June");
monthList.add("July");
monthList.add("August");
monthList.add("September");
monthList.add("October");
monthList.add("Novemebr");
monthList.add("December");
monthAdapter = new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item, monthList);
monthAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
}