как отобразить окно повторного просмотра с помощью диспетчера сетки в дочернем представлении в расширяемом списке просмотра - PullRequest
0 голосов
/ 16 ноября 2018

Я работаю над расширяемым списком, который работает нормально. Теперь я хочу показать gridLayoutManager с recyclerView в дочернем представлении, которое не работает нормально. enter image description here

Мне нужен этот тип меню, когда я нажимаю на категорию, тогда подкатегория будет отображаться с сеткой или линейным макетом с горизонтальным scrollView. Код адаптера:

@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {

    final ChildCategory child = (ChildCategory) getChild(groupPosition, childPosition);
    int Id = child.getId();
    String name = child.getName();
    if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater) this._context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.childs, parent, false);
    }
    childCate = new ArrayList<>();
    childCate.add(new ChildCategory(Id,name));
    rvCategory = convertView.findViewById(R.id.rvCategory);
    InnerRecyclerViewAdapter adapter = new InnerRecyclerViewAdapter(_context,childCate);
    rvCategory.setLayoutManager(new LinearLayoutManager(_context,LinearLayoutManager.HORIZONTAL,false));
    rvCategory.setAdapter(adapter);
    adapter.notifyDataSetChanged();
    Log.e("List",childCate.toString());
    for (int i=0;i<childCate.size();i++){
        Log.e("name",name );
    }
    return convertView;
}

Код InnerRecyclerViewAdapter:

public class InnerRecyclerViewAdapter extends RecyclerView.Adapter<InnerRecyclerViewAdapter.ViewHolder> {
private ArrayList<ChildCategory> child;
Context context;
int groupPosition;
String groupname;

public InnerRecyclerViewAdapter(Context context,ArrayList<ChildCategory> child) {
    this.child = child;
    this.context=context;
}

public class ViewHolder extends RecyclerView.ViewHolder {
    TextView name;
    CardView cardView;

    public ViewHolder(View itemView) {
        super(itemView);
        name = itemView.findViewById(R.id.itemTextView);
        cardView=itemView.findViewById(R.id.cardView);
    }
    public void setData(final ChildCategory childCategory){
        name.setText(childCategory.getName());
    }
}

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View v = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.card_expand_item_view, parent, false);
    InnerRecyclerViewAdapter.ViewHolder vh = new InnerRecyclerViewAdapter.ViewHolder(v);
    return vh;
}

@Override
public void onBindViewHolder(ViewHolder holder, final int position) {
    holder.setData(child.get(position));
}

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

}

где я делаю ошибку.

...