Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The method show(FragmentManager, String) in the type DialogFragment is not applicable for the arguments (FragmentTransaction, String)

I have a problem with Fragments.

Problem what i am facing is, i have a simple DialogFragment

public class Fragment3 extends DialogFragment  {
private Fragment activity;
ViewGroup root;

static Fragment3 newInstance() {
    Fragment3 f = new Fragment3();
    return f;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {        
    root = (ViewGroup) inflater.inflate(R.layout.fragment3_layout, container, false);
    return root;
  } 
}  

And i want to create this Fragment from another Fragment

public class ListViewImageAdapter extends BaseAdapter {

private Fragment activity;
....

public ListViewImageAdapter(Fragment activity, ArrayList<Object> listImages) {
    this.activity = activity;
 ...}

....
FragmentTransaction ft = activity.getFragmentManager().beginTransaction();
Fragment3 newFragment = Fragment3.newInstance();
newFragment.show( ft, "dialog");
....

But I get a message:

The method show(FragmentManager, String) in the type DialogFragment is not applicable for the arguments (FragmentTransaction, String)
like image 529
zond Avatar asked Feb 07 '14 11:02

zond


People also ask

How to check DialogFragment is showing?

that should mean its in the foreground displaying if im not mistaken. If you call DialogFragment's creation several times in one moment, dialogFragment = getSupportFragmentManager(). findFragmentByTag("dialog"); will return null, and all dialogs will be shown.

How to close DialogFragment?

tl;dr: The correct way to close a DialogFragment is to use dismiss() directly on the DialogFragment. Control of the dialog (deciding when to show, hide, dismiss it) should be done through the API here, not with direct calls on the dialog. Dismiss the fragment and its dialog.

What is the function of the FragmentManager?

The FragmentManager manages the fragment back stack. At runtime, the FragmentManager can perform back stack operations like adding or removing fragments in response to user interactions. Each set of changes are committed together as a single unit called a FragmentTransaction .


2 Answers

import android.support.v4.app.FragmentActivity;

instead of:

import android.app.DialogFragment;

(or the reverse)

like image 73
ms2r Avatar answered Oct 11 '22 20:10

ms2r


Try to call newFragment.show( activity.getFragmentManager(), "dialog"); instead of newFragment.show( ft, "dialog"); . DialogFragment.show() method takes FragmentManager as first argument, not FragmentTransaction. Please take a look on tutorial

like image 33
amukhachov Avatar answered Oct 11 '22 22:10

amukhachov