Each tab has an EditText with an id
in tab1.xml it's edit1
<EditText
android:id="@+id/edit1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
and it's edit2 in tab2.xml
<EditText
android:id="@+id/edit2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
tab1.xml and tab2.xml also has a button which can be clicked. It has the same id if you want on tab1 and tab2.
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/knop"
android:onClick="klik"/>
The item that matters is the OnClick. It point to a piece of code which must be implemented in the MainActivity.java code
public void klik(View v){
alert("Just an alert.");
String val1 = ((EditText) findViewById(R.id.edit1)).getText().toString();
String val2 = ((EditText) findViewById(R.id.edit2)).getText().toString();
alert(val1);
alert(val2);
alert(val1 + val2);
}
At last the alert routine
private void alert(String message){ //mies
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Alert");
alertDialog.setMessage(message);
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.show();
}
In fact the fragments can be treated as one page. You can retrieve the information from each field by id from the calling main page, in this case MainActivity.java.