我正在使用共享偏好设置,以便在单击按钮时始终检查ckeckbox。但我收到错误,未知类型' getChecked'。 ,代码是给出的:
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final SharedPreferences sharedPreferences = this.getSharedPreferences("pref", 0);
boolean checkedSearch = sharedPreferences.getBoolean("checkedSearch", false);
Button button = (Button) dialog.findViewById(R.id.button);
final CheckBox checkBox1 = (CheckBox) dialog.findViewById(R.id.checkBox1);
checkBox1.setChecked(checkedSearch ? true : false );
button.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
if(
checkBox1.getChecked()==false){
checkBox1.setChecked(true);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("checkedSearch",true)
.commit();
}
答案 0 :(得分:0)
final SharedPreferences sharedPreferences=this.getSharedPreferences("pref", 0);
你错过了=签名