I am getting an error
The method
show(FragmentManager, String)
in the typeDialogFragment
is not applicable for the arguments(FragmentManager, String)
package com.example.test1;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentActivity;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void click(View view) {
DialogFragment newFragment = new FireMissilesDialogFragment();
newFragment.show(getFragmentManager(), "missiles");
}
public boolean onCreateOtionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
As you're using android.support.v4.app.DialogFragment
, you should pass to show()
an instance of android.support.v4.app.FragmentManager
which can be queried using an getSupportFragmentManager()
call. Hope this helps.
The problem is because you need to be using the support package's FragmentManager but you are using the native FragmentManager when you call getFragmentManager(). Try calling getSupportFragmentManager() when initializing your variable fm
you also have to make sure that you include DialogFragment from the Support package and not from the native package.
You can do that by importing,
import android.support.v4.app.DialogFragment;
Even i had the same problem when running the code in gingerbread. But works fine for ICS. The solution is,
instead of this:
public class MainActivity extends Activity {
}
use extends FragmentActivty
public class MainActivity extends FragmentActivity {
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With