显示为preference屏幕额外的信息,当复选框preference汇总字段不够长? [英] Show extra info for Preference screens when CheckboxPreference summary field is not enough long?

查看:268
本文介绍了显示为preference屏幕额外的信息,当复选框preference汇总字段不够长?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个屏幕,你可以让我的Andr​​oid应用程序/禁用模块。

I have a screen where you can enable/disable modules for my Android application.

对于这个我用一个复选框preference屏幕。这一切都是好的,但汇总字段被切断,如果更详细的描述中加入比2行。

For this I use a CheckboxPreference screen. This is all good, but the summary field gets cut off if longer descriptions are added than 2 lines.

假设我有4-5线可说明每个模块的,我想在一个辅助窗口中显示此。

Suppose I have 4-5 lines of description available for each module, I would like to display this in a helper window.

我试图绑定一个click事件的复选框preference,但火灾的整条生产线,这样不仅复选框被点击的时候,更多的,无论你一下就行的复选框被触发。

I tried to bind a click event to the CheckboxPreference, but that fires for the whole line, so not only when the checkbox is clicked, and more, wherever you click on the line the checkbox is toggled.

所以,现在我想知道,如果这可以是固定的。因此,如果用户需要更多的信息,只是水龙头文字和助手打开了,如果想要切换设置,它水龙头的复选框。

So now I am wondering if this can be fixed. So if the user needs more info, just taps the text and the helper opens up, and if want to toggle the settings it taps the checkbox.

你会怎么做呢?我打开其他的想法也一样,如果他们做的工作。

How would you do it? I am open to other ideas too, if they do work.

推荐答案

HMN今天有同样的问题。 我的另一种解决方案是只允许显示摘要中额外的文本。

Hmn had the same problem today. My alternative solution is to just allow to display more Text within the summary.

刚刚创建自己的复选框preference子类,它看起来是这样的:

Just create your own subclass of CheckBoxPreference that looks something like this:

public class CheckBoxPreferenceWithLongSummary extends CheckBoxPreference{

    public CheckBoxPreferenceWithLongSummary(Context context) {
        super(context);
    }

    public CheckBoxPreferenceWithLongSummary(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    public CheckBoxPreferenceWithLongSummary(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onBindView(View view) {
        super.onBindView(view);
        TextView summaryView = (TextView) view.findViewById(android.R.id.summary);
        summaryView.setMaxLines(10);
    }
}

然后在你的preferenceScreen(我假设你使用XML来设置preference布局 - 不知道,如果它甚至有可能完全编程)刚刚取代旧<复选框preference ... /> 您的新的实现,比如< com.example.whatever.CheckBox preferenceWithLongSummary ... />

Then within your PreferenceScreen (i assume you use xml to set up the Preference layout - not sure if its even possible completely programmatically) just replace the old <CheckBoxPreference.../> with your new implementation like <com.example.whatever.CheckBoxPreferenceWithLongSummary ... />

好像工作只是对我很好,altough我不知道有关findViewById(android.R.id.summary),因为在父类com.android.internal.R.id.summary用于这似乎是不能直接从Java访问?希望它不只是一个巧合:)

Seems to work just fine for me, altough i'm not sure about the findViewById(android.R.id.summary) because in the parentClass com.android.internal.R.id.summary is used which seems to be not directly accessible from within Java? Hope its not just an coincidence :)

这篇关于显示为preference屏幕额外的信息,当复选框preference汇总字段不够长?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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