自定义Dialog中用SharedPreferences的问题 现在想实现 弹出一个dialog给用户提示然后有一个checkbox让用户选择 下次可以不再提醒这个消息 也就是说在自定义Dialog中用SharedPreferences 无解啊现在 高手帮 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 dialog中的是checkbox如果checkbox被选中的话 再去写SharedPreferences 顶楼上 我dialog里用的就是checkbox 能说的详细点吗 有什么帖子之类的吗 dialog要开启时 判断SharedPreferences里的键值是否为true,true就不打开dialog要关闭时 将checkbox的状态写入SharedPreferences <CheckBox xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:id="@+id/checkbox" android:layout_height="warp_content" android:text="下次不再提示"/>private void showDialog(){ SharedPreferences sp=getSharedPreferences("per", MODE_PRIVATE); boolean isCheck=sp.getBoolean("isCheck",false); if(isCheck){ View myView=LayoutInflater.from(this).inflate(R.layout.checkbox, null); CheckBox checkBox=(CheckBox)myView.findViewById(R.id.checkbox); new AlertDialog.Builder(this) .setView(myView) .create() .show(); checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if(isChecked){ Editor editor=sp.edit(); editor.putBoolean("isCheck",isChecked); editor.commit(); } } });楼主试试吧! 菜鸟求解! Android ListView滚动卡 自定义VIEW,加载出错,求指点 简易的短信收发软件开发 大家帮我看看这个错误说明了啥? Android平台自动化测试DEMO视频 对象怎么置为null值?obj=null后,obj==null返回false 求android入门教程 android实现下载文件功能,在保存文件的时候报Permission denied Android 4.X的手机如何获取菜单栏高度啊 求android俄罗斯方块源码 我要在非sdcard 上写一个文件,让其他所有应用都有权限访问?
如果checkbox被选中的话 再去写SharedPreferences
dialog要关闭时 将checkbox的状态写入SharedPreferences
android:layout_width="fill_parent"
android:id="@+id/checkbox"
android:layout_height="warp_content"
android:text="下次不再提示"/>private void showDialog(){
SharedPreferences sp=getSharedPreferences("per", MODE_PRIVATE);
boolean isCheck=sp.getBoolean("isCheck",false);
if(isCheck){
View myView=LayoutInflater.from(this).inflate(R.layout.checkbox, null);
CheckBox checkBox=(CheckBox)myView.findViewById(R.id.checkbox);
new AlertDialog.Builder(this)
.setView(myView)
.create()
.show();
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked){
Editor editor=sp.edit();
editor.putBoolean("isCheck",isChecked);
editor.commit();
}
}
});
楼主试试吧!