现在想实现 弹出一个dialog给用户提示然后有一个checkbox让用户选择 下次可以不再提醒这个消息 也就是说在自定义Dialog中用SharedPreferences 无解啊现在 高手帮
解决方案 »
- Android手机与蓝牙模块通信,出现数据差错的问题
- android 扑克类游戏请教
- android gridview点击实现页面跳转
- spinner左右键无法获取焦点什么原因,如何解决
- listview控件怎样显示数据库数据?
- 关于eclipse下开发android,弹出成员函数是暴卡的问题,原来是ADT的问题!
- 请教一个关于ffmpeg Deinterlace的问题
- android 4.0以上的版本 怎样读写外置sd卡?
- fragment 如何向 activity 传递数据
- RecyclerView+ViewPager的实现问题
- 求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();
}
}
});
楼主试试吧!