Dialogfragment With Custom Listview
Solution 1:
Instead of using onCreateView
you should be overriding onCreateDialog
and inside of it, it'll look something like:
@Overridepublic Dialog onCreateDialog(Bundle savedInstanceState) {
Collections.addAll(mOfficeListItems, getResources().getStringArray(R.array.offices));
Viewv= getActivity().getLayoutInflater().inflate(R.layout.fragment_choice_list, null);
mLocationList = (ListView)v.findViewById(R.id.location_criteria_list);
finalFunctionListArrayAdapteradapter=newFunctionListArrayAdapter(
this, android.R.layout.simple_list_item_1, mOfficeListItems);
mLocationList.setAdapter(adapter);
AlertDialog.Builderbuilder=newAlertDialog.Builder(getActivity());
builder.setTitle(getArguments().getInt("title")).setView(v);
return builder.create();
}
This quote from the DialogFragment
documentation page describes what you're trying to do:
Implementations should override this class and implement
onCreateView(LayoutInflater, ViewGroup, Bundle)
to supply the content of the dialog. Alternatively, they can overrideonCreateDialog(Bundle)
to create an entirely custom dialog, such as anAlertDialog
, with its own content.
In your case, it seems like onCreateDialog
is the way to go since you want to do a custom inner view.
Solution 2:
May be you are missing something very small but important. Are you missing notifyDataSetChanged()
in your adapter?
"Once you have added the new item to the adapter you have to call notifyDataSetChanged()
so that the listview
refreshes itself with the new set of data found in the adapter."
Solution 3:
what I forgot was:
view.setAdapter(adapter);
after I added that the code worked
Post a Comment for "Dialogfragment With Custom Listview"