我正在尝试在我的preferenceActivity中实现一个自定义按钮,但是当我点击它时没有发生任何事情,我不知道我缺少什么,这是我的整个PreferenceActivity类,我试过到目前为止:
public class FiltrarActivity extends PreferenceActivity {
private String preferencesName = "";
private ActionBar actionBar;
private String defaultValue;
private Preference mResetButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SecurePreferences mSessao = new SecurePreferences(getApplicationContext(), "sessao");
String menuAtual = (mSessao.getString("menuAtual") != null) ? mSessao.getString("menuAtual") : "Pedidos";
setTitle("Filtrar " + menuAtual);
actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
preferencesName = getIntent().getExtras().getString(NavigationMain.FILTRO);
// set the preferences file name
getPreferenceManager().setSharedPreferencesName(preferencesName);
if (menuAtual.equals("Viagens")) {
} else if (menuAtual.equals("Pedidos")) {
addPreferencesFromResource(R.xml.filtrar);
final ListPreference pData = (ListPreference) findPreference("prefData");
final ListPreference pStatus = (ListPreference) findPreference("prefStatus");
mResetButton = findPreference("prefReset");
mResetButton.setOnPreferenceClickListener(new OnPreferenceClickListener(){
@Override
public boolean onPreferenceClick(Preference preference) {
System.out.println("OK");
return false;
}
});
pData.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
// @Override
public boolean onPreferenceChange(Preference preference,
Object newValue) {
SharedPreferences customSharedPreference = getSharedPreferences("prefData", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = customSharedPreference.edit();
editor.putString("listentries", (String) newValue);
editor.commit();
System.out.println("Escolheu >>> " + newValue);
return true;
}
});
pStatus.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
// @Override
public boolean onPreferenceChange(Preference preference,
Object newValue) {
SharedPreferences customSharedPreference = getSharedPreferences("prefStatus", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = customSharedPreference.edit();
editor.putString("listStatus", (String) newValue);
editor.commit();
System.out.println("Escolheu >>> " + newValue);
return true;
}
});
} else if (menuAtual.equals("Clientes")) {// codigo
}
}
}
XML:
<PreferenceCategory android:title="@string/fReset">
<Preference
android:layout="@layout/dialog_reset"
android:key="prefReset"
android:summary="" />
</PreferenceCategory>