How can I show this :
public class TagsDialog extends DialogFragment
{
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
builder.setView(inflater.inflate(R.layout.tags_dialog, null));
builder.setMessage("This is a message").setTitle("TAGS");
return builder.create();
}
}
From inside my Fragment
inside a ViewPager
:
public class MyFragment extends Fragment
{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
...
ImageView btnTags = (ImageView)view.findViewById(R.id.btnTags);
btnTags.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
DialogFragment dlg = new TagsDialog();
//this line doesn't compile
dlg.show(getSupportFragmentManager(), "tags");
}
});
}
}
I have tried for ages to get this to work, but getSupportFragmentManager
is never resolved... any ideas?
EDIT:
I feel this is all caused by the support FragmentManager vs the android.app.FragmentManager, however I do not know how to solve this, as I am using the ViewPager from the support library...
getSupportFragmentManager/and all related getFragManager methods like parent and child one always returns the Manager from the support lib, wheras the show method wants the core one.
Imports are:
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
FragmentManager fm = getActivity().getSupportFragmentManager(); // returns from support lib
DialogFragment dlg = new TagsDialog();
dlg.show(fm, "tags"); // wants core...
If I just use core, then getSupportFragmentManager()
does not exist on getActivity()
...
You should double check your imports. You can't use a mix of Fragment & FragmentManager from the support library and from android core apis.
If you use support, use everything from support (from package android.support.v4.app
). If not, use everything from core api package (android.app
).