android6.1

### oefening 1 ###

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <LinearLayout
        android:layout_width="368dp"
        android:layout_height="495dp"
        android:orientation="vertical"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="8dp">
    </LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

Download hier het bestand.
### oefening 2 ###

### activity_main.xml ###

<LinearLayout

    ...

    <RadioGroup
        android:id="@+id/myRadioGroup"
        android:layout_width="254dp"
        android:layout_height="123dp" >

        <RadioButton
            android:id="@+id/radioButtonBeste"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Beste" />

        <RadioButton
            android:id="@+id/radioButtonMijnheer"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Mijnheer" />

        <RadioButton
            android:id="@+id/radioMevrouw"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Mevrouw" />
    </RadioGroup>

    <Button
            android:id="@+id/button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Bereken leeftijd"
            android:onClick="startSecondActivity"/>

    ...
    
</LinearLayout>

Download hier het bestand.
### oefening 3 ###

### activity_main2.xml ###

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout...>

	...

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    ...

</androidx.constraintlayout.widget.ConstraintLayout>

### MainActivity.java ###

public class MainActivity extends AppCompatActivity {

    public static final String RADIO_MESSAGE = "aanhef_gebruiker";

    private RadioGroup radioGroup;
    private String selectedString;
    private RadioButton besteId, mevrouwId;

    ...

    public void startSecondActivity (View view) {

//      Intent
        Intent intent = new Intent(this, Main2Activity.class);

//      Aanhef
        radioGroup = (RadioGroup) findViewById(R.id.myRadioGroup);
        besteId = (RadioButton) findViewById(R.id.radioButtonBeste);
        mevrouwId = (RadioButton) findViewById(R.id.radioMevrouw);

        int selectedId = radioGroup.getCheckedRadioButtonId();

        if (selectedId == besteId.getId()){
            selectedString = "Beste";
        } else if (selectedId == mevrouwId.getId()){
            selectedString = "Mevrouw";
        } else {
            selectedString = "Mijnheer";
        }

        intent.putExtra(RADIO_MESSAGE, selectedString);

//      Activity starten
        startActivity(intent);
    }

    ...
}

### Main2Activity ###

public class Main2Activity extends AppCompatActivity {

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

        ...

        Intent intent = getIntent();
        String aanhef = intent.getStringExtra(MainActivity.RADIO_MESSAGE);
        TextView textView = (TextView) findViewById(R.id.textView);
        textView.setText(aanhef);

        ...
    }
}

Download hier het bestand.