Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
301 views
in Technique[技术] by (71.8m points)

android - I have some radio groups with two radio buttons in each now in the next activity I want to record all the inputs.I am a newbie

I am trying to build an android app in which there are two activities in the first activity I have some radio groups with two radio buttons each. So user selects one of the two radio buttons now in the next activity I have to show which radio buttons are selected from each group.

package com.example.eAttendance;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public abstract class MainActivity extends AppCompatActivity {
    public static final String EXTRA_TEXT = "com.example.eAttendance.EXTRA_TEXT";

    /*public void clickSubmit(View view) {

        openActivity2();

    }
    public void openActivity2() {
        Intent intent = new Intent(this, MainActivity2.class);
        intent.putExtra("radioGroup1Selected", selectedRadioValue);
        startActivity(intent);
    }
    */

    //RadioGroup rg = (RadioGroup) findViewById(R.id.radioGroup1);
    //String selectedRadioValue = ((RadioButton)findViewById(rg.getCheckedRadioButtonId())).getText().toString();
    RadioGroup rg;


    public void resetBtn(View view) {
        RadioGroup x=findViewById(R.id.radioGroup1);
        x.clearCheck();

        RadioGroup y=findViewById(R.id.radioGroup2);
        y.clearCheck();

        RadioGroup z=findViewById(R.id.radioGroup3);
        z.clearCheck();
    }

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

        rg = findViewById(R.id.radioGroup1);
        RadioButton radioId1 = findViewById(rg.getCheckedRadioButtonId());
        String textStatus = radioId1.getText().toString();

        Button btn = findViewById(R.id.button1);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, MainActivity2.class);
                intent.putExtra(EXTRA_TEXT,textStatus);
                startActivity(intent);
            }
        });

    }
}

Why this code is not working and the emulator is not opening.
question from:https://stackoverflow.com/questions/65862108/i-have-some-radio-groups-with-two-radio-buttons-in-each-now-in-the-next-activity

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...