Android 复选框首选项和跳过活动

Android 复选框首选项和跳过活动,android,checkbox,sharedpreferences,android-linearlayout,Android,Checkbox,Sharedpreferences,Android Linearlayout,我有一个对话框自定义布局,我包括了一些文本视图和图像,但我有一个复选框,我希望能够使这个对话框弹出,如果用户选中了应用程序/活动的第一个初始启动器上的复选框 我不知道我现在的代码到底从哪里开始,任何建议或更正都将非常有帮助和感激 你开悟了吗 公共类您是否开展了启蒙活动{ 按钮是; 按钮编号; 公共静态最终字符串PREFS\u NAME=“MyPrefsFile1”; 公共复选框不再显示; @凌驾 创建时受保护的void(Bundle savedInstanceState){ //TODO自动生成

我有一个对话框自定义布局,我包括了一些文本视图和图像,但我有一个复选框,我希望能够使这个对话框弹出,如果用户选中了应用程序/活动的第一个初始启动器上的复选框

我不知道我现在的代码到底从哪里开始,任何建议或更正都将非常有帮助和感激

你开悟了吗
公共类您是否开展了启蒙活动{
按钮是;
按钮编号;
公共静态最终字符串PREFS\u NAME=“MyPrefsFile1”;
公共复选框不再显示;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_Areyou启蒙);
dontshowreach=(复选框)findviewbyd(R.id.checkBox1);
最终按钮yes=(按钮)findViewById(R.id.continuebutton);
yes.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v){
//单击后执行操作
字符串checkBoxResult=“未选中”;
if(dontshowreach.isChecked())
checkBoxResult=“checked”;
SharedReferences设置=GetSharedReferences(首选项名称,0);
SharedReferences.Editor=settings.edit();
putString(“skipMessage”,checkBoxResult);
//提交编辑!
commit();
返回;
}
});
SharedReferences设置=GetSharedReferences(首选项名称,0);
String skipMessage=settings.getString(“skipMessage”,“未选中”);
如果(!skipMessage.equals(“checked”)){
//如果(skipMessage!=(“选中”))
最终按钮编号=(按钮)findViewById(R.id.learnmore);
no.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v){
//单击后执行操作
Intent i=newintent(Intent.ACTION_视图,Uri.parse(“vnd.youtube:3S6PTpCyW1I”);
List List=getPackageManager().QueryInputActivities(i,PackageManager.MATCH_DEFAULT_仅限);
if(list.size()==0){
//默认youtube应用程序不存在或不符合我们知道的标准
//利用我们自己的活动
i=新的意图(getApplicationContext(),AreYouDivision.class);
//i.putExtra(“3S6PTpCyW1I”,videoID);
}
星触觉(i);
}
});
}
活动\u areyouedin.xml
您的“是”按钮有什么用?现在,它只保存当前复选框状态。您最好在复选框上设置OnCheckedChangeListener

如果用户以前启用了跳过框,则将执行If子句

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_areyouenlighten);

    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
    SharedPreferences.Editor editor = settings.edit();

    if (settings.getBoolean("skipMessage", false) {
         // skipping message, so eg. start another activity here
         Intent in = ...
         startActivity(in);
         return;
    }

    CheckBox dontShowAgain = (CheckBox) findViewById(R.id.checkBox1);
    dontShowAgain.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            editor.putBoolean("skipMessage", isChecked);
            editor.commit();
        }
    });


    ...

}

当用户禁用通知时,要做什么或显示什么?@ottel142当前唯一发生的事情是复选框被启用,然后单击时,我的对话框仍然会每次填充。@ottel142我试图使用此复选框为用户保存首选项,以便他们看不到此对话框活动。或者仅启用此活动首次安装时,y启动器1次。当打开应用程序时,弹出此对话框(活动),用户可以单击按钮a或b来处理其他活动(a和b),此复选框用于跳过此第一个活动并直接转到活动a。此对话框仅在首次启动时弹出,以允许用户禁用它,然后在下次重新安装应用程序之前,他们将永远不会看到它
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:orientation="vertical" >

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="8dp"
    android:paddingTop="10dp"
    android:src="@drawable/logoheader" />

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="fill_parent"
    android:layout_height="3dp"
    android:layout_weight="1"
    android:src="@color/dialog_text" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="15dp"
    android:text="Hello, World" />



<CheckBox
    android:id="@+id/checkBox1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:paddingRight="10dp"
    android:text="Disable This Notification" />

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:paddingTop="15dp" >

    <Button
        android:id="@+id/continuebutton"
        android:layout_width="120dp"
        android:layout_height="wrap_content"
        android:text="Continue" />

    <Button
        android:id="@+id/learnmore"
        android:layout_width="120dp"
        android:layout_height="wrap_content"
        android:text="Learn More" />
  </LinearLayout>

</LinearLayout>
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_areyouenlighten);

    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
    SharedPreferences.Editor editor = settings.edit();

    if (settings.getBoolean("skipMessage", false) {
         // skipping message, so eg. start another activity here
         Intent in = ...
         startActivity(in);
         return;
    }

    CheckBox dontShowAgain = (CheckBox) findViewById(R.id.checkBox1);
    dontShowAgain.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            editor.putBoolean("skipMessage", isChecked);
            editor.commit();
        }
    });


    ...

}