Inflating A Recyclerview Inside A Dialog Layout
In my activity, on click of a button I am opening a Dialog which has a RecyclerView in it. final Dialog dialog = new Dialog(MyActivity.this); dialog.setTitle('Details'); dialog.set
Solution 1:
I have figured out the problem. After setting layout manager in recyclerview, it works fine.
LinearLayoutManagerlayoutManager=newLinearLayoutManager(dialog.getContext());
layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
detailsRecyclerView.setLayoutManager(layoutManager);
Solution 2:
The problem is that the Dialog
is already created when you try to modify the adapter, because of that It's not getting populated with your data.
You have two options, create your own Dialog
which extend Dialog
class and in onCreate()
put your code to populate the list or add adapter.notifyDataSetChanged()
after setAdapter()
to tell that your data inside the list was updated.
Solution 3:
Use a dialog fragment instead of Dialog. An dialog fragment gives all the features of a dialog while providing the functionality of a fragment.
publicclassAlertDialogFragmentextendsDialogFragment {
@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//inflate layout with recycler viewViewv= inflater.inflate(R.layout.details_popup, container, false);
RecyclerViewdetailsRecyclerView= (RecyclerView) getActivity().findViewById(R.id.detailsRecyclerView);
DetailsAdapterdetailsAdapter=newDetailsAdapter(R.layout.detail_item, feedbackResponseSubList);
detailsRecyclerView.setAdapter(detailsAdapter);
detailsRecyclerView.setLayoutManager(newLinearLayoutManager(getActivity()));
return v;
}
public Dialog onCreateDialog(Bundle SavedInstanceState) {
//The rest of the code you will get when u search for dialogfragments
Post a Comment for "Inflating A Recyclerview Inside A Dialog Layout"