dimanche 5 juin 2016

How to create a Google Keep Style RecyclerView child item that has Checkboxes

I am looking for a way to have RecylverView child items display a list of Checkboxs as seen in the Google Keep application. I have tried using nested recyclverView within the chcil item. It has worked but the problem is that the child item will not expand due to the fact that the RecyclverView can natrurally scroll to show the hidden content.

I have ready about adding an adpater to a linearlayout that will add the checkboxes in the child item. Here the code for what I have done so far. private Context context; private LayoutInflater inflater;

private  List<ShoppingListItem> itemList= new ArrayList<>();
private LinearAdapter adapter;

public OuterRecyclerViewAdapter(Context context) {
    this.context = context;
}

public void setShoppingListItems(List<ShoppingListItem> shoppingList) {
    this.itemList = shoppingList;
   adapter= new LinearAdapter(itemList,context);
}

@Override
public OuterRecylerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    inflater=LayoutInflater.from(context);
    View view=inflater.inflate(R.layout.shopping_item,parent,false);
    return new OuterRecylerViewHolder(view);
}

@Override
public void onBindViewHolder(OuterRecylerViewHolder holder, int position) {

    adapter.initialiseViews();
    holder.linearLayout.addView(adapter.getView());

    Log.v("On binder", "OnBinder called");
}

@Override
public int getItemCount() {
    return itemList.size();
}

public class OuterRecylerViewHolder extends RecyclerView.ViewHolder{
   LinearLayout linearLayout;
    View mView;

    public OuterRecylerViewHolder(View itemView) {
        super(itemView);
        mView=itemView;
        linearLayout=(LinearLayout)itemView.findViewById(R.id.linearlayout);
   Log.v("OuterRecycler Called","view holder");
    }
}

  public   class LinearAdapter{
    LinearLayout linearLayout;
    Context context;
    LayoutInflater inflater;
    View view;
    List<ShoppingListItem> itemList= new ArrayList<>();

    public LinearAdapter( List<ShoppingListItem> itemList, Context context) {
        //this.linearLayout = linearLayout;
        this.itemList = itemList;
        this.context = context;
    }

    public void initialiseViews(){
        inflater=LayoutInflater.from(context);
        view=inflater.inflate(R.layout.product_litem_inner, linearLayout, false);
         //ItemViewHolder itemViewHolder= new ItemViewHolder(view);
        //onBind(itemViewHolder,itemList);
   view=onBind(view,itemList);
    }

  public View getView() {
      return view;
  }

  public View  onBind(View view,List<ShoppingListItem> list){
        for (int i=0;i<list.size();i++){
            CheckBox checkBox=(CheckBox)view.findViewById(R.id.checkBox);

            ShoppingListItem item=list.get(i);
            checkBox.setText(item.getItem());


        }

        return view;

    }




Aucun commentaire:

Enregistrer un commentaire