Tengo un par de implementaciones personalizadas DialogPreference
que flotan alrededor, como this one:Preferencia personalizada, targetSdkVersion = "11": ¿sangría faltante?
package apt.tutorial;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.TimePicker;
public class TimePreference extends DialogPreference {
private int lastHour=0;
private int lastMinute=0;
private TimePicker picker=null;
public static int getHour(String time) {
String[] pieces=time.split(":");
return(Integer.parseInt(pieces[0]));
}
public static int getMinute(String time) {
String[] pieces=time.split(":");
return(Integer.parseInt(pieces[1]));
}
public TimePreference(Context ctxt) {
this(ctxt, null);
}
public TimePreference(Context ctxt, AttributeSet attrs) {
this(ctxt, attrs, 0);
}
public TimePreference(Context ctxt, AttributeSet attrs, int defStyle) {
super(ctxt, attrs, defStyle);
setPositiveButtonText("Set");
setNegativeButtonText("Cancel");
}
@Override
protected View onCreateDialogView() {
picker=new TimePicker(getContext());
return(picker);
}
@Override
protected void onBindDialogView(View v) {
super.onBindDialogView(v);
picker.setCurrentHour(lastHour);
picker.setCurrentMinute(lastMinute);
}
@Override
protected void onDialogClosed(boolean positiveResult) {
super.onDialogClosed(positiveResult);
if (positiveResult) {
lastHour=picker.getCurrentHour();
lastMinute=picker.getCurrentMinute();
String time=String.valueOf(lastHour)+":"+String.valueOf(lastMinute);
if (callChangeListener(time)) {
persistString(time);
}
}
}
@Override
protected Object onGetDefaultValue(TypedArray a, int index) {
return(a.getString(index));
}
@Override
protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
String time=null;
if (restoreValue) {
if (defaultValue==null) {
time=getPersistedString("00:00");
}
else {
time=getPersistedString(defaultValue.toString());
}
}
else {
time=defaultValue.toString();
}
lastHour=getHour(time);
lastMinute=getMinute(time);
}
}
Ellos trabajan muy bien. Sin embargo, en una aplicación con android:targetSdkVersion="11"
definido, en un XOOM, muestran perdiendo el guión cuando en el PreferenceActivity
:
Además, el tamaño de la fuente aparece una pizca más grande, al menos por el título.
No hay nada en DialogPreference
donde realmente estoy anulando cualquier comportamiento de formato para esas cosas, AFAIK. El XML preferencia es nada especial, aparte de referirse a la clase anterior:
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<ListPreference
android:key="sort_order"
android:title="Sort Order"
android:summary="Choose the order the list uses"
android:entries="@array/sort_names"
android:entryValues="@array/sort_clauses"
android:dialogTitle="Choose a sort order" />
<CheckBoxPreference
android:key="alarm"
android:title="Sound a Lunch Alarm"
android:summary="Check if you want to know when it is time for lunch" />
<apt.tutorial.TimePreference
android:key="alarm_time"
android:title="Lunch Alarm Time"
android:defaultValue="12:00"
android:summary="Set your desired time for the lunch alarm"
android:dependency="alarm" />
<CheckBoxPreference
android:key="use_notification"
android:title="Use a Notification"
android:defaultValue="true"
android:summary="Check if you want a status bar icon at lunchtime, or uncheck for a full-screen notice"
android:dependency="alarm" />
</PreferenceScreen>
Alguien sabe dónde voy mal?
Gracias!
ACTUALIZACIÓN
Here is a link to a project que contiene esta preferencia costumbre y un simple archivo XML de preferencias que demuestra el problema. Incluso con solo dos clases de Java, XML de preferencia y un archivo arrays.xml
, obtengo este fenómeno. Here is a compiled APK de este proyecto.
Hay que ir a pedir la marca Murphy - lo sabe todo :) – JohnnyLambada
@JohnnyLambada: lo he intentado, pero la oficina principal Green Bay Packers se negó a comentar. Oh espera. ¿No quisiste decir http://goo.gl/KNYOu? :-) – CommonsWare
Siempre es bueno tener el mismo problema que Mark Murphy. Si no puede resolverlo fácilmente, entonces no me siento tan mal. – Intrications