我使用按钮PreferenceActivity
创建了Preference out
并指定了她的活动。
我需要清除用户名和密码(我只清除了Preference)并转到片段"授权"。我的片段来自
android.support.v4.app.Fragment;
android.support.v4.app.FragmentManager;
我无法从getFragmentManager();
android.support.v4.app.FragmentManager
(PreferenceActivity
)
public class PrefActivity extends PreferenceActivity {
Preference out;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref);
out = findPreference("logout");
out.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
FragmentManager fragmentManager = getFragmentManager();
Fragment auth = new AuthDialog();
Bundle arg = new Bundle();
arg.putString("login", "");
arg.putString("password", "");
auth.setArguments(arg);
fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
fragmentManager.beginTransaction().replace(R.id.content_frame, auth).commit();
SharedPreferences sPref = PreferenceManager.getDefaultSharedPreferences(getApplication());
sPref.edit().clear().commit();
return false;
}
});
}
}
答案 0 :(得分:0)
PreferenceActivity
从android.app.Activity
延伸而不是android.support.v4.app.Activity
。听起来很奇怪,没有办法使用带有PreferenceActivity的v4片段。您最好的选择是使用this library