gpt4 book ai didi

android - PreferenceFragmentCompat 不监听第一次触摸事件

转载 作者:行者123 更新时间:2023-11-29 02:35:45 24 4
gpt4 key购买 nike

我创建了一个 PreferenceFragmentCompat 设置,一切正常,但我注意到有些奇怪,当加载首选项屏幕时第一次单击设置按钮,我触摸了一些首选项,但它没有响应我的第一次触摸,但是正常工作后,这是我的代码

public class SettingsFragment extends PreferenceFragmentCompat implements HomeActivity.Authentication, Preference.OnPreferenceClickListener, SharedPreferences.OnSharedPreferenceChangeListener, ConfirmAlertDialog.OnDialogClickInterface {
@Override
public boolean onPreferenceClick(final Preference preference) {
final String key = preference.getKey();

switch (key) {
case "remove_ads":
homeActivity.purchaseRemoveAds();
break;
case "hide_icon":
try {
homeActivity.loadFragment(new HideOptiosTutorial(), getParentFragment().getFragmentManager().beginTransaction());
} catch (Exception e) {
e.printStackTrace();
}
break;

case "key_share_app_link":
shareAppFile();

break;

case "move_to_sdcard":

showMovetoSdDialog();

break;
case "button_internal":

showMovetoInternalDialog();

break;
case "back_up_sdcard":
if (isSDCardUnmounted()) {
showSDCardMountError();
} else {

globalPasswords = getBackupPasswords();

if (!FileUtilis.isSafAllowed(getActivity())) {
showSDCardNotAllowedDialog(983);
//
return false;
}

if (globalPasswords.size() == 0) {
showNoBackupFoundMsg();
} else {
showDialogToBackupFromSDCard();
}
}
break;
case "change_password":
showChangePinDialog();
break;

case "key_rate_us":
rateApplication();
break;
case "app_link":
SavedAlbumsFragment.showAppLockLink(getActivity());
break;
case "view_intruders":
startActivity(new Intent(homeActivity, ViewIntruders.class));
break;
case "theme":
showSelectTehmeDialog();
break;

case "enter_email":

showChangeEmailDialog();
break;
}


return false;
}
@Override
public void onCreatePreferences(Bundle bundle, String s) {
addPreferencesFromResource(R.xml.pref_headers);
Log.e("Mateen","onCreatePreferences");

homeActivity = ((HomeActivity) getActivity());
homeActivity.addAuthenticationListner(this);
localDatabase = LocalDatabase.getInstance(getActivity());
localPreferences = new LocalPreferences(getActivity());

getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
LocalBroadcastManager.getInstance(homeActivity).registerReceiver(broadcastReceiver,new IntentFilter("Remove_Is_Purchased"));

removeAdsPref=findPreference("remove_ads");
mCategory = (PreferenceCategory)findPreference("cat_remove_ads");



if (localPreferences.IsRemovedAdsPurchased())
{
mCategory.removePreference(removeAdsPref);
getPreferenceScreen().removePreference(mCategory);
}
else
{
removeAdsPref.setOnPreferenceClickListener(this);
}

findPreference("move_to_sdcard").setOnPreferenceClickListener(this);
findPreference("view_intruders").setOnPreferenceClickListener(this);
findPreference("button_internal").setOnPreferenceClickListener(this);
findPreference("back_up_sdcard").setOnPreferenceClickListener(this);
findPreference("change_password").setOnPreferenceClickListener(this);
findPreference("key_rate_us").setOnPreferenceClickListener(this);
findPreference("app_link").setOnPreferenceClickListener(this);
findPreference("hide_icon").setOnPreferenceClickListener(this);
findPreference("key_share_app_link").setOnPreferenceClickListener(this);
findPreference("listPref_wrong_tries").setOnPreferenceClickListener(this);
findPreference("theme").setOnPreferenceClickListener(this);
findPreference("enter_email").setOnPreferenceClickListener(this);




if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
findPreference("key_cam_short").setVisible(false);
findPreference("key_vid_short").setVisible(false);
}

if (!PreferenceManager.getDefaultSharedPreferences(homeActivity).getBoolean("key_intruder_detection",false))
{
findPreference("listPref_wrong_tries").setEnabled(false);
}
if (!Reprint.isHardwarePresent()) {
findPreference("key_fingerprint").setEnabled(false);
}

if (!FileUtilis.isSdcardPresent(getActivity())) {
findPreference("move_to_sdcard").setEnabled(false);
findPreference("button_internal").setEnabled(false);
findPreference("back_up_sdcard").setEnabled(false);

// findPreference("change_password").setEnabled(false);
findPreference("always_save_to_sdcard").setEnabled(false);
}
//add xml

}

这是我的偏好 xml:

<android.support.v7.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.andr]oid.com/apk/res-auto"
app:key="preferenceScreen">

<!-- These settings headers are only used on tablets. -->z
<android.support.v7.preference.PreferenceCategory android:title="@string/cate_remove_ads"
android:key="cat_remove_ads">
<Preference
android:key="remove_ads"
android:summary="@string/txt_remove_ads"
android:title="@string/remove_ads" />
</android.support.v7.preference.PreferenceCategory>

<android.support.v7.preference.PreferenceCategory android:title="@string/storage">

<Preference
android:key="move_to_sdcard"
android:summary="@string/export_sdcard_summary"
android:title="@string/txt_move_to_external" />

<Preference
android:key="button_internal"
android:summary="@string/export_internal_summary"
android:title="@string/txt_move_too_internal" />

<Preference
android:key="back_up_sdcard"
android:summary="@string/backup_summary"
android:title="@string/back_from_sdcard" />

<android.support.v7.preference.SwitchPreferenceCompat
android:defaultValue="false"
android:key="always_save_to_sdcard"
android:summary="@string/always_on_sd_card"
android:title="@string/sav_loc" />

</android.support.v7.preference.PreferenceCategory>


<android.support.v7.preference.PreferenceCategory android:title="@string/cate_security">


<Preference
android:key="hide_icon"
android:title="@string/hide_icon" />


<Preference
android:key="app_link"
android:summary="@string/app_link_title"
android:title="@string/app_link_detail" />

<Preference
android:key="change_password"
android:title="@string/chagne_password" />

<Preference
android:key="enter_email"
android:title="@string/forgot_email_title"
android:summary="@string/enter_email_to_recover" />


<android.support.v7.preference.SwitchPreferenceCompat
android:defaultValue="false"
android:key="shuffle_pin"
android:summary="@string/shuffle_summary"
android:title="@string/shuffle_title" />

<android.support.v7.preference.SwitchPreferenceCompat
android:defaultValue="false"
android:key="key_fingerprint"
android:summary="@string/summary_fingerprint"
android:title="@string/fingerprint_auth" />
</android.support.v7.preference.PreferenceCategory>

<android.support.v7.preference.PreferenceCategory android:title="@string/cate_intruder">
<android.support.v7.preference.SwitchPreferenceCompat
android:defaultValue="false"
android:key="key_intruder_detection"
android:summary="@string/take_intruder_picture_summary"
android:title="@string/take_intruder_picture" />

<android.support.v7.preference.ListPreference
android:defaultValue="3"
android:entries="@array/wrong_tries"
android:entryValues="@array/wrong_tries"
android:summary="%s"
android:title="@string/wrong_tries"
android:key="listPref_wrong_tries" />
<Preference
android:key="view_intruders"
android:summary="@string/show_intruder_pic"
android:title="@string/show_intruder_pic_summary" />
</android.support.v7.preference.PreferenceCategory>

<android.support.v7.preference.PreferenceCategory android:title="@string/cate_others">
<Preference
android:key="theme"
android:summary="@string/chose_theme"
android:title="@string/select_theme" />


<android.support.v7.preference.SwitchPreferenceCompat
android:defaultValue="false"
android:key="key_cam_short"
android:summary="@string/cam_short_detail"
android:title="@string/sec_selfi_shortcut" />

<android.support.v7.preference.SwitchPreferenceCompat
android:defaultValue="false"
android:key="key_vid_short"
android:summary="@string/vid_short_detail"
android:title="@string/sec_vid_shortcut" />

<Preference
android:key="key_share_app_link"
android:summary="@string/share_app_link_detail"
android:title="@string/share_app_link_title" />

<Preference
android:key="key_rate_us"
android:summary="@string/rate_detail"
android:title="@string/rate_us" />
</android.support.v7.preference.PreferenceCategory>

请指导我我做错了什么?是支持库问题还是我做错了什么?

最佳答案

似乎是支持库错误。在更新应用程序 gradle 依赖项以支持库 27.0.0 后,它按预期工作

implementation 'com.android.support:appcompat-v7:27.0.0'
implementation 'com.android.support:preference-v14:27.0.0'
implementation 'com.android.support:support-v13:27.0.0'

关于android - PreferenceFragmentCompat 不监听第一次触摸事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47224232/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com