I have a DialogFragment that shows a list of items to select (similar to the dialog application in Messaging).
My problem is that I cannot turn off this dialog when an item is selected. I tried calling dismiss() and getDialog().dismiss() inside OnItemClickListener , no luck. I tried to delete the dialog via FragmentManager, I tried fragmentManager.popBackStack() , all to no avail. I can not turn off this dialog. It goes well when you click outside the dialog box or click the back button, but nothing in my code will make it go away.
Has anyone seen this before? How can I cancel the dialog correctly?
Dialog Code:
public class ShareDialog extends DialogFragment { public enum ShareType { Camera, Gallery, Web, Whiteboard, Browse, } BaseAdapter mShareAdapter = new BaseAdapter() { @Override public View getView(int position, View contentView, ViewGroup parent) { TextView view = null; if (contentView == null) { view = (TextView) getLayoutInflater(null).inflate(android.R.layout.simple_list_item_1, parent, false); } else { view = (TextView) contentView; } int draw = 0; switch (ShareType.values()[position]) { case Browse: view.setText("Browse Content..."); draw = R.drawable.ic_share_browse; break; case Camera: view.setText("Image from Camera..."); draw = R.drawable.ic_share_camera; break; case Gallery: view.setText("Image from Gallery..."); draw = R.drawable.ic_share_gallery; break; case Web: view.setText("New Browsing Session"); draw = R.drawable.ic_share_web; break; case Whiteboard: view.setText("New Whiteboard"); draw = R.drawable.ic_share_whiteboard; break; } view.setCompoundDrawablesWithIntrinsicBounds(draw, 0, 0, 0); view.setCompoundDrawablePadding(8); return view; } @Override public long getItemId(int position) { return ShareType.values()[position].ordinal(); } @Override public Object getItem(int position) { return ShareType.values()[position]; } @Override public int getCount() { return ShareType.values().length; } }; public Dialog onCreateDialog(android.os.Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle("Share which?"); ListView list = new ListView(getActivity()); list.setAdapter(mShareAdapter); list.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long itemId) { dismiss();
source share