本文介绍了无法从preferenceFragment显示小吃吧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用小吃吧onShared preferenceChange()由活动主办我的preferenceFragment内。

I want to use Snackbar onSharedPreferenceChange() inside my PreferenceFragment hosted by a Activity.

preference.xml

    <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    android:key="ll_main">
<PreferenceCategory android:title="@string/push_notification">
    <SwitchPreference android:title="@string/transectional_notification"
        android:key="trans_not"
        android:defaultValue="true"
        android:summary="@string/get_notified_about_any_changes_related_to_your_transections"/>
    <SwitchPreference android:title="@string/promotional_notification"
        android:key="prom_not"
        android:defaultValue="true"
        android:summary="@string/get_notified_about_referalls"/>
</PreferenceCategory>
    <PreferenceCategory android:title="@string/other_notifications">
        <SwitchPreference android:title="@string/email_notifications"
            android:defaultValue="true"
            android:key="email_not" />
        <SwitchPreference android:title="@string/sms_notifications"
            android:defaultValue="true"
            android:key="sms_not"/>
    </PreferenceCategory>
<PreferenceCategory android:title="@string/recommendation_setting">
    <com.til.recharger.widgets.PhoneEditTextPreference
        android:title="@string/mobile_no"
        android:inputType="number"
        android:summary="8587035342"
        android:key="mob_no_edit"/>
    <ListPreference android:title="@string/operator"
        android:summary="Airtel"
        android:key="operator_list"/>
    <ListPreference android:title="@string/circle"
        android:summary="New Delhi"
        android:key="circle_list"/>
    <ListPreference
        android:title="Plan type"
        android:entries="@array/listentries"
        android:entryValues="@array/listentries"
        android:summary="Postpaid"
        android:defaultValue="Prepaid"
        android:key="plan_key"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/plan_info">
    <com.til.recharger.widgets.NumberPickerPreference
        android:title="@string/bill_cycle"
        android:summary="2"
        android:persistent="true"
        android:key="bill_cycle_edit"/>
    <com.til.recharger.widgets.CustomEditTextPreference
        android:title="@string/monthly_data_limit"
        android:summary="%s"
        android:inputType="number"
        android:key="monthly_limit_edit"/>
    <ListPreference
        android:title="@string/preffered_network_type"
        android:entries="@array/mobiledataoptions"
        android:entryValues="@array/mobiledatavalues"
        android:summary="3G"
        android:defaultValue="3G"
        android:key="pref_data_list"/>
</PreferenceCategory>
</PreferenceScreen>

我为显示小吃店的功能是:

My function for showing snackbar is :

    public void hideKeyWithError(final String error) {
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            AppUtils.hide_keyboard(getActivity());
            Snackbar.make(view,error,Snackbar.LENGTH_LONG).show();
        }
    }, (300));
}

我不知道该怎么传的观看到小吃店来证明这一点。

I don't know what to pass as 'view' to snackbar to show it.

PS:我想通过preferenceScreen到小吃吧,但是没有成功。提前致谢。

PS : I tried passing PreferenceScreen to Snackbar, But didn't work out. Thanks in Advance.

推荐答案

试试这个为获取视图

View view = getView();

所以,code为。

So the code is.

public void hideKeyWithError(final String error) {
new Handler().postDelayed(new Runnable() {
    @Override
    public void run() {
        View view = getView();
        AppUtils.hide_keyboard(getActivity());
        Snackbar.make(view,error,Snackbar.LENGTH_LONG).show();
    }
}, (300));
}

这篇关于无法从preferenceFragment显示小吃吧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-10 20:57