2011-01-10 26 views
1

我正在構建某種嚮導以在同步和管理帳戶中創建用戶帳戶。我使用ViewFlipper,我的活動必須是AccountAuthenticatorActivity。這就是說這也意味着我不能繼承PreferenceActivity。如何在視圖中顯示首選項

所以我在PreferenceActivity的代碼,擡頭一看,我認爲它應該是可能有從的ListView繼承PreferenceView。就我所知,PreferenceActivity的Activity部分並不是真的需要。

雖然PreferenceManager是真正塊我。

private PreferenceManager onCreatePreferenceManager() { 
    PreferenceManager preferenceManager = new PreferenceManager(this, FIRST_REQUEST_CODE); 
    preferenceManager.setOnPreferenceTreeClickListener(this); 
    return preferenceManager; 
} 

該函數意味着我們可以使用operator new來安裝PreferenceManager。顯然,sdk隱藏了PreferenceManager的構造函數。我有點困惑。

有沒有辦法來擡高我的喜好,沒有PreferenceActivity顯示它們?

回答

1

有沒有辦法擴大我的喜好,並顯示他們沒有PreferenceActivity?

不通過SDK,AFAIK。

由於您既未顯示也未修改此嚮導中的首選項(「我正在構建某種嚮導以在Sync和Manage帳戶中創建用戶帳戶」),我不知道爲什麼要使用Preference對象,無論如何。只需使用常規小部件。

+0

什麼?我試圖給他們看,所以我可以編輯它們。我的問題中有什麼不明確的地方?該向導的最後一步是設置帳戶的首選項以進行同步。我確實有一個包含首選項的xml文件,它會在其他一些地方使用。 – 2011-01-10 03:38:02

0

是,啓動可能需要一個AccountAuthenticatorActivity,但我相信,反過來,可以啓動它想任何活動。 AccountAuthenticatorActivity不一定必須顯示自己的GUI。

這是我們如何做到這一點;收到開始偏好活動的addAccount請求。意圖被分析以查看是否請求了新帳戶並顯示適當的GUI。嚮導完成後,結果通過結果Intent傳回。

/* 
    * The user has requested to add a new account to the system. We return 
    * an intent that will launch our login screen if the user has not 
    * logged in yet, otherwise our activity will just pass the user's 
    * credentials on to the account manager. 
    */ 
    @Override 
    public Bundle addAccount(AccountAuthenticatorResponse response, 
      String accountType, String authTokenType, 
      String[] requiredFeatures, Bundle options) 
      throws NetworkErrorException { 
     Bundle result = new Bundle(); 
     Intent i = new Intent(mContext, PrefsActivity.class); 
     i.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, 
       response); 
     i.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, 
       ServerPrefsFragment.class.getName()); 
     result.putParcelable(AccountManager.KEY_INTENT, i); 
     return result; 
    } 

編輯:剛剛意識到我並沒有完全回答這個問題。我們選擇做你想做的解決方案實際上如下所示;不向嚮導使用PreferenceActivity,而使用上面顯示的addAccount函數調用的標準活動。

相關問題