如何处理点击事件在android系统preferences如何处理、事件、系统、android

2023-09-06 11:29:17 作者:谁为谁画地为牢

 public class SettingsActivity extends PreferenceActivity implements OnPreferenceClickListener{


private Preference mLoginPreference;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.settings_layout);

    mLoginPreference = getPreferenceManager().findPreference(
            getString(R.string.login_pref));
}

@Override
public boolean onPreferenceClick(Preference preference) {

    if(preference.getKey().equals(getString(R.string.login_pref))) {
        Intent intent = new Intent(SettingsActivity.this, FacebookLoginActivity.class);
        startActivity(intent);
        return true;
    }
    return false;
}
}

在settings_layout.xml

In settings_layout.xml

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@android:color/white" >

<Preference
    android:key="@string/login_pref"
    android:title="@string/login_title" />
</PreferenceScreen>

我有一个应用程序,它为设置屏幕,在这个登录您的账户选项是存在的,这将登录FB帐户的用户和总结将被更新。这里是一个code我写的,但它不工作,我也想​​更新的总结登录到您的帐户用户是否登录或不使用脸书账号。任何帮助,谢谢

I have an app which as settings screen, In this Login to your Account option is there which will login FB account of the user and summary will be updated. Here is a code I written, but it is not working and also i want to update the summary of the Login to your Account whether user is logged in or not using FaceBook Account. Any Help, Thanks

推荐答案

一旦登录,在 FacebookLoginActivity 做,你可以通过设置结果code 的setResult 完成活动之前和内部(结果code) SettingsActivity 覆盖的onActivityResult (结果code)和更改用户登录的标签。

Once login is done inside FacebookLoginActivity you can set the result code using setResult(Result code) before finishing the activity and inside SettingsActivity override onActivityResult(Result code) and change the label that user is logged in.