recycleview в диалоговом окне, как правильно сделать?

пробовал сделать по примеру от google, но есть проблемы. вот код. ``

public class DialogSelectFolderForSorting extends Dialog {

private RecyclerView recyclerView;
private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager layoutManager;

public DialogSelectFolderForSorting(@NonNull Context context) {
    super(context);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.folder_for_sorting);
    recyclerView = (RecyclerView) findViewById(R.id.recycler_view_select_folder);
    recyclerView.setHasFixedSize(true);

    String[] tt = new String[2];
    tt[0] = "test1";
    tt[1] = "test2";
    mAdapter = new AdapterSelectFolder(tt);
    recyclerView.setAdapter(mAdapter);

}
}

я не понимаю как правильно надо сделать. виджет recyclerview не отображается.

public class AdapterSelectFolder extends RecyclerView.Adapter<AdapterSelectFolder.MyViewHolder> {

    private String[] mDataSet;
    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        TextView v = (TextView) LayoutInflater.from(parent.getContext()).inflate(R.layout.items_recycler_view, parent, false);
        MyViewHolder vh = new MyViewHolder(v);
        return vh;
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        holder.textView.setText(mDataSet[position]);
    }

    public AdapterSelectFolder (String[] myDataSet){
        mDataSet = myDataSet;
    }

    @Override
    public int getItemCount() {
        return mDataSet.length;
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {
        public TextView textView;

        public MyViewHolder(@NonNull TextView itemView) {
            super(itemView);
            textView = itemView;
        }
    }

}

еще меня интересует вот этот кусок кода.

        TextView v = (TextView) LayoutInflater.from(parent.getContext()).inflate(R.layout.items_recycler_view, parent, false);
        MyViewHolder vh = new MyViewHolder(v);
        return vh;

здесь textview as v получает ссылку, но почему? там ведь в layout, как бы textview находится внутри элемента linearlayout.

вот layout.items_recycler_view.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="10dp"
        android:text="test"
        />
</LinearLayout>

вот folder_for_sorting.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:text="@string/button_cancel"
            />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:text="@string/button_ok"
            />
    </RelativeLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycler_view_select_folder"
        android:scrollbars="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
</LinearLayout>

Ответы (0 шт):