如何保存复选框状态? - 机器人 [英] How to save the checkbox state? - android
本文介绍了如何保存复选框状态? - 机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
雅有很多这个东西在网的问题和答案,但我只是无法弄清楚如何使用共享preference保存复选框状态。刚才有人帮我,我是不是能够做到的编码部分。
CH =(复选框)findViewById(R.id.checkBox1); ch.setOnClickListener(新View.OnClickListener(){ @覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
如果(ch.isChecked())
{
Toast.makeText(getApplicationContext(),检查,Toast.LENGTH_SHORT).show();
}
其他
{
Toast.makeText(getApplicationContext(),取消选中,Toast.LENGTH_SHORT).show();
}}
});
}
解决方案
只要创建共享prefrences和使用添加值 .putBoolean()
如果(ch.isChecked()){ 共享preferences设置= getShared preferences(preFRENCES_NAME,0);
settings.edit()putBoolean(检查,真).commit()。}
Ya there are plenty of questions and answers about this stuff in the net but i just can't figure out how to save the checkbox state using sharedpreference. Someone just help me with the coding part which i was not able to do.
ch = (CheckBox) findViewById(R.id.checkBox1);
ch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(ch.isChecked())
{
Toast.makeText(getApplicationContext(), "Check", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(getApplicationContext(), "Uncheck", Toast.LENGTH_SHORT).show();
}}
});
}
解决方案
Just create SharedPrefrences and Add value using .putBoolean()
if(ch.isChecked()){
SharedPreferences settings = getSharedPreferences(PREFRENCES_NAME, 0);
settings.edit().putBoolean("check",true).commit();
}
这篇关于如何保存复选框状态? - 机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文