📌  相关文章
📜  chkbox 另一个活动 - 任何代码示例

📅  最后修改于: 2022-03-11 14:55:18.756000             🧑  作者: Mango

代码示例1
package com.example.himanshu.checkbox_module;

    import android.content.Intent;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.CheckBox;
    import android.widget.TextClock;

    public class FirstActivity extends AppCompatActivity {

        Intent intentData;
        Button buttonSend;

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

            intentData = new Intent(FirstActivity.this,SecondActivity.class);

            buttonSend = (Button) findViewById(R.id.button1);

            buttonSend.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    startActivity(intentData);

                }
            });
        }

        public void onCheckedBox(View view){

            boolean checked = ((CheckBox)view).isChecked();

            switch (view.getId()){

                case R.id.mon:if (checked){
                    intentData.putExtra("MON","Monday");
                }else {
                    intentData.removeExtra("MON");
                }break;

                case R.id.tue:if (checked){
                    intentData.putExtra("TUE","Tuesday");
                }else {
                    intentData.removeExtra("TUE");
                }break;

                case R.id.wed:if (checked){
                    intentData.putExtra("WED","Wednesday");
                }else {
                    intentData.removeExtra("WED");
                }break;

                case R.id.thu:if (checked){
                    intentData.putExtra("THU","Thursday");
                }else {
                    intentData.removeExtra("THU");
                }break;

                case R.id.fri:if (checked){
                    intentData.putExtra("FRI","Friday");
                }else {
                    intentData.removeExtra("FRI");
                }break;

                case R.id.sat:if (checked){
                    intentData.putExtra("SAT","Saturday");
                }else {
                    intentData.removeExtra("SAT");
                }break;

                case R.id.sun:if (checked){
                    intentData.putExtra("SUN","Sunday");
                }else {
                    intentData.removeExtra("SUN");
                }break;

                default:break;

            }
        }
    }