I have trouble with this line:
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
The problem I am having is that (this)
has a red line. But the rest of the code is ok. What can be the problem here? Here is the rest of the code:
public static class ShowDataViewHolder extends RecyclerView.ViewHolder {
private final CheckedTextView image_title;
private final CheckBox chk;
public ShowDataViewHolder(final View itemView) {
super(itemView);
image_title = (CheckedTextView) itemView.findViewById(R.id.fetch_image_title);
chk = (CheckBox)itemView.findViewById(R.id.checkBox);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences();
final SharedPreferences.Editor editor = preferences.edit();
if (preferences.contains("checked") && preferences.getBoolean("checked", false) == true){
chk.setChecked(true);
}else{
chk.setChecked(false);
}
chk.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (chk.isChecked()){
editor.putBoolean("checked", true);
editor.apply();
}else{
editor.putBoolean("checked", false);
editor.apply();
}
}
});
}
private void Image_Title(String title) {
image_title.setText(title);
}
This class is inside my MainActivity.
Aucun commentaire:
Enregistrer un commentaire