自preference,targetSdkVersion =" 11":缺少缩进? [英] Custom preference, targetSdkVersion="11": missing indent?

查看:172
本文介绍了自preference,targetSdkVersion =" 11":缺少缩进?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个自定义的对话preference 实现左右浮动,如<一个href="https://github.com/commonsguy/cw-lunchlist/blob/master/19-Alarm/LunchList/src/apt/tutorial/Time$p$pference.java">this 之一:

I have a couple of custom DialogPreference implementations floating around, such as this one:

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);
    }
}

他们的工作就好了。然而,与 Android的应用程序:targetSdkVersion =11定义,在XOOM,他们表现出了缺少缩进时,在 preferenceActivity

They work just fine. However, in an application with android:targetSdkVersion="11" defined, on a XOOM, they show up missing the indent when in the PreferenceActivity:

此外,字体大小出现微幅下挫较大,至少在标题。

Also, the font size appears a smidge bigger, at least for the title.

有没有在对话框preference ,我真的很重写了这些东西任何格式的行为,AFAIK。在preference XML是不值一提,除了参考上述类:

There's nothing in DialogPreference where I am really overriding any formatting behavior for that stuff, AFAIK. The preference XML is unremarkable, other than referring to the above class:

<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>

任何人都知道我要去哪里错了?

Anyone know where I'm going wrong?

谢谢!

更新

这里是一个链接到一个项目包含此定制preference和演示该问题的简单preference XML文件。即使只有两个Java类中,preference XML,以及 arrays.xml 文件,我得到这个现象。 下面是该项目编译APK

Here is a link to a project that contains this custom preference and a simple preference XML file that demonstrates the problem. Even with just two Java classes, the preference XML, and an arrays.xml file, I get this phenomenon. Here is a compiled APK from this project.

推荐答案

(互调的<一个href="http://groups.google.com/group/android-developers/browse_frm/thread/47c0ebae23a7b864">associated Android的开发者线程)

OK,我想它了。

有一个preference三种可能的构造函数:

There are three possible constructors on a Preference:

MyPreference(Context ctxt)
MyPreference(Context ctxt, AttributeSet attrs)
MyPreference(Context ctxt, AttributeSet attrs, int defStyle)

某处沿线,我选择了具有高达格局 单参数构造链的双参数构造 (通过的第二个参数),并具有双参数 构造函数链中的三个参数的构造函数(传递0 第三个参数)。

Somewhere along the line, I picked up the pattern of having the one-parameter constructor chain to the two-parameter constructor (passing null for the 2nd parameter), and having the two-parameter constructor chain to the three-parameter constructor (passing 0 for the 3rd parameter).

和这不是正确的答案。

我希望,正确的答案是,只有实施第二 构造函数,因为正确的默认样式是内部到Android ( com.android.internal.R.attr.dialog preferenceStyle )。第二 构造函数是充气preference XML中使用的。

I am hoping that the right answer is to only implement the second constructor, because the correct default style is internal to Android (com.android.internal.R.attr.dialogPreferenceStyle). The second constructor is the one used with inflating preference XML.

感谢所有的帮助!

这篇关于自preference,targetSdkVersion =&QUOT; 11&QUOT;:缺少缩进?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆