现在想实现 弹出一个dialog给用户提示然后有一个checkbox让用户选择 下次可以不再提醒这个消息 也就是说在自定义Dialog中用SharedPreferences 无解啊现在 高手帮

解决方案 »

  1.   

    dialog中的是checkbox
    如果checkbox被选中的话 再去写SharedPreferences 
      

  2.   

    顶楼上 我dialog里用的就是checkbox 能说的详细点吗 有什么帖子之类的吗
      

  3.   

    dialog要开启时  判断SharedPreferences里的键值是否为true,true就不打开
    dialog要关闭时  将checkbox的状态写入SharedPreferences
      

  4.   

    <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();
                            }
    }
    });
    楼主试试吧!