當前位置: 首頁>>代碼示例>>Java>>正文


Java CheckBoxPreference.setKey方法代碼示例

本文整理匯總了Java中android.support.v7.preference.CheckBoxPreference.setKey方法的典型用法代碼示例。如果您正苦於以下問題:Java CheckBoxPreference.setKey方法的具體用法?Java CheckBoxPreference.setKey怎麽用?Java CheckBoxPreference.setKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.v7.preference.CheckBoxPreference的用法示例。


在下文中一共展示了CheckBoxPreference.setKey方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initSettings

import android.support.v7.preference.CheckBoxPreference; //導入方法依賴的package包/類
private void initSettings(){
    PreferenceScreen screen = getPreferenceScreen();

    for(int i = 0; i < courses.size(); i++){
        
        //Add all courses as a checkbox
        CheckBoxPreference cbp = new CheckBoxPreference(getContext());
        cbp.setPersistent(false);
        cbp.setTitle(courses.get(i).getCourseCode());
        cbp.setKey("" + courses.get(i).getId());
        cbp.setViewId(i);
        cbp.setOnPreferenceClickListener(this);

        if (courses.get(i).isFavorite()) {
            cbp.setChecked(true);
        }

        checkBoxes.add(cbp);
        screen.addPreference(cbp);
    }
}
 
開發者ID:andrmos,項目名稱:imber,代碼行數:22,代碼來源:SettingFavoriteCourseFragment.java

示例2: addAutoSyncProperty

import android.support.v7.preference.CheckBoxPreference; //導入方法依賴的package包/類
protected void addAutoSyncProperty(
        final IGISApplication application,
        final Account account,
        PreferenceGroup syncCategory)
{
    final String accountNameHash = "_" + account.name.hashCode();
    SharedPreferences sharedPreferences =
            mStyledContext.getSharedPreferences(Constants.PREFERENCES,
                    Constants.MODE_MULTI_PROCESS);

    CheckBoxPreference enablePeriodicSync = new CheckBoxPreference(mStyledContext);
    enablePeriodicSync.setKey(KEY_SYNC);
    enablePeriodicSync.setPersistent(false);
    enablePeriodicSync.setTitle(R.string.auto_sync);

    boolean isAccountSyncEnabled = isAccountSyncEnabled(account, application.getAuthority());
    enablePeriodicSync.setChecked(isAccountSyncEnabled);
    enablePeriodicSync.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
    {
        @Override
        public boolean onPreferenceChange(
                Preference preference,
                Object newValue)
        {
            boolean isChecked = (boolean) newValue;
            setAccountSyncEnabled(account, application.getAuthority(), isChecked);
            return true;
        }
    });

    long timeStamp = sharedPreferences.getLong(
            com.nextgis.maplib.util.SettingsConstants.KEY_PREF_LAST_SYNC_TIMESTAMP
                    + accountNameHash, 0);
    if (isAccountSyncEnabled && timeStamp > 0) {
        enablePeriodicSync.setSummary(ControlHelper.getSyncTime(mStyledContext, timeStamp));
    } else {
        enablePeriodicSync.setSummary(R.string.auto_sync_summary);
    }
    syncCategory.addPreference(enablePeriodicSync);
}
 
開發者ID:nextgis,項目名稱:android_maplibui,代碼行數:41,代碼來源:NGWSettingsFragment.java

示例3: populateNewsSources

import android.support.v7.preference.CheckBoxPreference; //導入方法依賴的package包/類
private void populateNewsSources() {
    PreferenceCategory newsSourcesPreference = (PreferenceCategory) findPreference("card_news_sources");

    NewsManager newsManager = new NewsManager(mContext);
    List<NewsSources> newsSources = newsManager.getNewsSources();
    final NetUtils net = new NetUtils(mContext);
    for (NewsSources newsSource: newsSources) {
        final CheckBoxPreference pref = new CheckBoxPreference(mContext);
        pref.setKey("card_news_source_" + newsSource.getId());
        pref.setDefaultValue(true);
        // Load news source icon in background and set it
        final String url = newsSource.getIcon();

        if (url != null) { // Skip News that do not have a image
            new Thread(() -> {
                final Optional<Bitmap> bmp = net.downloadImageToBitmap(url);
                mContext.runOnUiThread(() -> {
                    if (bmp.isPresent()) {
                        pref.setIcon(new BitmapDrawable(getResources(), bmp.get()));
                    }
                });
            }).start();
        }

        pref.setTitle(newsSource.getTitle());
        if(newsSourcesPreference!=null) {
            newsSourcesPreference.addPreference(pref);
        }
    }
}
 
開發者ID:TCA-Team,項目名稱:TumCampusApp,代碼行數:31,代碼來源:SettingsFragment.java


注:本文中的android.support.v7.preference.CheckBoxPreference.setKey方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。