Android帐户首选项:如何添加“修改帐户”按钮?

时间:2014-06-12 13:11:04

标签: android android-preferences account

我最近刚为我的应用实施了一些自定义帐户功能。 添加帐户工作正常。

现在,如果我创建了一个帐户并在Android设置中选择了我的帐户类型,我想在那里打开一个按钮,可以打开ActivityDialog来修改帐户。

我没有为这样一个按钮找到一个“干净”的解决方案,并且达到了古怪的解决方法。目前我正在尝试创建一个不会设置任何值的自定义偏好设置,但会在可以设置onClickListener的设置中提供一个视图。

然而,我甚至无法使最简单的Preference子类起作用; 当我使用我的自定义Preference,然后在Android设置中选择我的帐户类型时,设置有时只是关闭,但大多数时候我得到一个Android错误 “设置已关闭”。

这对我有什么帮助,或者更好的方法来获得这个按钮, 或指向我收到此错误的原因的指针, 或者一种调试方法,因为我没有在logcat中收到任何错误消息。

我的自定义偏好:

public class RSSSEditPreference extends CheckBoxPreference
{
    public RSSSEditPreference(final Context context, final AttributeSet attrs)
        {
        super(context, attrs);
        }
}

我使用的preferences.xml

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <CheckBoxPreference
        android:key="show_password"
        android:title="@string/setup_show_password"
        android:defaultValue="false" />
    <net.roughdesign.rsss.account.RSSSEditPreference
        android:key="show_another_thing"
        android:title="@string/setup_show_password"
        android:defaultValue="false" /> 
</PreferenceScreen>

如果我在preferences.xml中注释掉我的自定义首选项,它就可以。

这是LogCat为一次运行显示的内容(安装,启动,关闭,尝试设置):

06-12 15:19:01.375: I/Timeline(18100): Timeline: Activity_launch_request id:net.roughdesign.rsss time:71954753
06-12 15:19:01.649: D/OpenGLRenderer(18100): Enabling debug mode 0
06-12 15:19:01.813: I/Timeline(18100): Timeline: Activity_idle id: android.os.BinderProxy@41aabb78 time:71955189
06-12 15:19:02.125: I/Timeline(18100): Timeline: Activity_idle id: android.os.BinderProxy@41aabb78 time:71955507
06-12 15:19:05.750: I/Timeline(18100): Timeline: Activity_idle id: android.os.BinderProxy@41aabb78 time:71959126
06-12 15:19:15.469: I/Timeline(18100): Timeline: Activity_idle id: android.os.BinderProxy@41aabb78 time:71968840

1 个答案:

答案 0 :(得分:0)

似乎LogCat只是显示了发生的一小部分 重新启动IDE(Eclipse)后,我现在可以在LogCat中看到错误消息,所以我可以继续。

此外,我想要实现的目标可以通过在首选项XML文件中向首选项添加意图来完成,如下所述:
http://developer.android.com/guide/topics/ui/settings.html#Intents

相关问题