Friday, 6 September 2013

DialogFragment not showing, it opens and closes very quickly

DialogFragment not showing, it opens and closes very quickly

The DialogFragment I'm trying to create won't stay open. When I step
through it, it opens and then closes again right away.
My onCreateDialog keeps telling me that my current targetSdk is 8, but
I've changed it back and forth to 11 multiple times, even restarted
Android Studio, but still tells me it's wrong.
So far all the other posts I've found related to this haven't answered my
question. I haven't been able to get FragmentActivity to work. Here's my
code:
ShowUpgradeDialogFragment class:
public class ShowUpgradeDialogFragment extends DialogFragment {
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(R.string.dialog_builder_message)
.setPositiveButton(R.string.dialog_builder_positive, new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// upgrade
}
})
.setNegativeButton(R.string.dialog_builder_negative, new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
}
});//*/
System.out.println ("hello");
// Create the AlertDialog object and return it
AlertDialog dialog = builder.create();
return dialog;
}
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ila.tax_shield"
android:versionCode="18" android:versionName="3.2.4">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18"/>
<fragment android:name=".ShowUpgradeDialogFragment"
android:label="@string/app_name"
android:windowIsFloating="true"
android:background="@android:color/transparent"
android:screenOrientation="portrait">
</fragment>
// remaining manifest
</manifest>
my onCreate method:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DialogFragment newFragment = new ShowUpgradeDialogFragment();
newFragment.show(getFragmentManager(), "dialog");
// code
}
Thanks in advance for your help!

No comments:

Post a Comment