Ich habe einen DatePicker in meiner App, die immer auf beiden Handys und Tablets bis Android 6 gearbeitet hat. Ich habe einen Samsung Galaxy 7 Edge t Test an und der Dialog wird nicht angezeigt.Android DatePicker Dialog nicht auf Android 6
Ich habe die min und Ziel sdk Version auf 11 und 21 im Manifest festgelegt.
Ich verstehe, dass ich DialogFragment verwenden sollte, aber gibt es einen Grund, warum der Code unten auf Android 6 nicht angezeigt wird? Der Code funktioniert bei 2.3.6, 4.x und 5.x einwandfrei.
Das folgende Protokoll wird ausgeführt, daher weiß ich, dass die Methode .show() aufgerufen wurde.
Log.e(TAG, "Just executed dialog.show() and at the end of showDateTimeDialog method");
[EDIT] Dinge, die ich versucht habe, sind:
einen Stil der style.xml Hinzufügen und die einen anderen Dialog Konstruktor aufrufen, die diesen Stil verweist. Dies zeigt einen Dialog auf Android 6, aber leider ist es nicht mein eigener, der das my-Layout mit Schaltflächen verwendet.
<style name="MyDialogStyle" parent="Theme.AppCompat.Light">
.
dialog = new Dialog(MenuActivity2.this, R.style.MyDialogStyle);
dialog.setContentView(R.layout.datetimepickerunalloc);
Dank
Button Set;
Button ReSet;
Button Cancel;
DatePicker DPic;
TextView Date;
private ViewSwitcher switcher;
static final int DATE_TIME_DIALOG_ID = 999;
Dialog dialog;
TextView dialogMessage;
DateTime timeSetOnSpinner;
public void showDateTimeDialog() {
// final Calendar c = Calendar.getInstance();
final SimpleDateFormat dfDate = new SimpleDateFormat("dd-MMM-yyyy HH:mm");
dialog = new Dialog(MenuActivity2.this);
dialog.setContentView(R.layout.datetimepickerunalloc);
DPic = (DatePicker) dialog.findViewById(R.id.DatePicker);
Set = ((Button) dialog.findViewById(R.id.SetDateTime));
Set.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Calendar c = Calendar.getInstance();
c.set(DPic.getYear(), DPic.getMonth(), DPic.getDayOfMonth());
timeSetOnSpinner = new DateTime(c);
DateTimeFormatter fmt = DateTimeFormat.forPattern("d-MMM-Y");
String formattedDate = fmt.print(timeSetOnSpinner);
formattedDate = formattedDate.trim();
//Toast.makeText(MenuActivity2.this, "date = " + formattedDate, Toast.LENGTH_LONG).show();
final Intent intent = new Intent(MenuActivity2.this, ShowUnallocatedCallsActivity.class);
intent.putExtra("unallocdate", formattedDate);
startActivity(intent);
}// end of onClick
});
ReSet = ((Button) dialog.findViewById(R.id.ResetDateTime));
ReSet.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Calendar c = Calendar.getInstance();
DPic.updateDate(c.get(Calendar.YEAR), c.get(Calendar.MONTH),
c.get(Calendar.DAY_OF_MONTH));
}
});
dialog.setTitle("Unallocated calls date");
try {
ReSet.performClick();
dialog.show();
Log.e(TAG, "Just executed dialog.show() and at the end of showDateTimeDialog method");
} catch (Exception e) {
// ignore
}
}// showDateTimeDialog()
.
Das ist mein Layout für den benutzerdefinierten Dialog
<?xml version="1.0" encoding="UTF-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="700dp"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/textviewdatetimepickermessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
<LinearLayout
android:id="@+id/DateLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<DatePicker
android:id="@+id/DatePicker"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip" />
</LinearLayout>
<LinearLayout
android:id="@+id/ControlButtons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="10dip" >
<Button
android:id="@+id/SetDateTime"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@android:string/ok" />
<Button
android:id="@+id/ResetDateTime"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Reset" />
<!--
<Button
android:layout_height="wrap_content"
android:layout_width="0dip"
android:id="@+id/CancelDialog"
android:text="@android:string/cancel"
android:layout_weight="1"/>
-->
</LinearLayout>
</LinearLayout>
</ScrollView>
.
können Sie den Stack-Trace anstelle von // ignore im Fang von dialog.show(); und sehen, ob eine Ausnahme auf Android 6 – androidLover
@androidLover ausgelöst wird Hallo, ich habe den Stacktrace mit dem Versuch/Fang entfernt veröffentlicht. Es gibt keine Ausnahme. – turtleboy