RecyclerView в BottomSheet не отображается - PullRequest
0 голосов
/ 03 февраля 2020

Я хочу создать bottomSheet, где у меня есть recyclerView. Проблема в том, что он не показывает мой recyclerview. Где может быть проблема? Это мой bottomSheet класс.

public class MyBottomSheetDialogFragment extends BottomSheetDialogFragment {

public static final String TAG = "ActionBottomDialog";
private Context context;


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


@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.layout_wishlist_move_to, container, false);
    final RecyclerView recyclerView = view.findViewById(R.id.recycler_bottom_sheet_move_to);

    List<String> list = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        list.add("Birthday " + i);
    }

    Adapter mAdapter = new Adapter(list);
    recyclerView.setAdapter(mAdapter);

    return view;
}


private class Adapter extends RecyclerView.Adapter<Adapter.BottomSheetHolder> {

    private List<String> myList;

    private Adapter(List<String> list) {
        this.myList = list;
    }

    @NonNull
    @Override
    public Adapter.BottomSheetHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(context);
        return new BottomSheetHolder(inflater.inflate(R.layout.item_wishlist_bottom_sheet, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull Adapter.BottomSheetHolder holder, int position) {
        if (myList.size() == 0) return;

        holder.labelTitleCategory.setText(myList.get(position));
        holder.labelImage.setImageResource(R.drawable.ic_icon);
    }


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


    private class BottomSheetHolder extends RecyclerView.ViewHolder {
        final TextView labelTitleCategory;
        final ImageView labelImage;

        public BottomSheetHolder(@NonNull View itemView) {
            super(itemView);
            labelTitleCategory = itemView.findViewById(R.id.title);
            labelImage = itemView.findViewById(R.id.image);
        }
    }
}
}

А вот класс, в котором я показываю диалог.

button.setOnClickListener(v -> {
            MyBottomSheetDialogFragment dialogWish = new MyBottomSheetDialogFragment(getContext());
            dialogWish.show(getFragmentManager(), WishListBottomSheetDialogFragment.TAG);
        });

Ответы [ 2 ]

1 голос
/ 03 февраля 2020

Вы должны установить компоновщик для reyclerView

LinearLayoutManager linearLayoutManager=new LinearLayoutManager(context,LinearLayoutManager.VERTICAL,false); reyclerView.setLayoutManager(linearLayoutManager)

1 голос
/ 03 февраля 2020

Вам нужно добавить менеджер раскладки в окно реселлера, чтобы показать элемент, так что

recyclerView.setLayoutManager(new LinearLayoutManager(context);

По умолчанию будет создан менеджер раскладки по вертикали для показа элементов по вертикали, хотя можно использовать по горизонтали и сетке в шахматном порядке. ясли эт c

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...