### 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" android:orientation="vertical" tools:context=".MainActivity"> <TableLayout android:layout_width="match_parent" android:layout_height="match_parent"> <TableRow android:layout_width="match_parent" android:layout_height="match_parent" > <EditText android:id="@+id/etnLeeftijd" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="10" android:hint="Vul uw leeftijd in" android:inputType="numberSigned" /> <TextView android:id="@+id/tvLeeftijd" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </TableRow> <TableRow android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:id="@+id/btnOK" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="btnOK" android:text="OK" /> </TableRow> </TableLayout> </androidx.constraintlayout.widget.ConstraintLayout>
Download hier het bestand.
### oefening 2 ###
public void btnOK(View view) {
...
// Leeftijd
EditText etnLeeftijd = (EditText)findViewById(R.id.etnLeeftijd);
int leeftijd = Integer.parseInt(etnLeeftijd.getText().toString());
String strLeeftijd;
if (leeftijd < 18 ) { strLeeftijd = "wel recht op kinderbijslag"; } else { strLeeftijd = "geen recht op kinderbijslag"; } TextView tvLeeftijd = (TextView)findViewById((R.id.tvLeeftijd)); tvLeeftijd.setText(strLeeftijd); ... }[/javascript]
Download hier het bestand.
### oefening 3 ### public void btnOK(View view) { ... // Leeftijd EditText etnLeeftijd = (EditText)findViewById(R.id.etnLeeftijd); int leeftijd = Integer.parseInt(etnLeeftijd.getText().toString()); String strLeeftijd; if (leeftijd < 18 ) { strLeeftijd = "wel recht op kinderbijslag"; } else if (leeftijd > 67 ){ strLeeftijd = "recht op AOW"; } else { strLeeftijd = "geen recht op kinderbijslag"; } TextView tvLeeftijd = (TextView)findViewById((R.id.tvLeeftijd)); tvLeeftijd.setText(strLeeftijd); ... }
Download hier het bestand.