In this exercise you are going to make an application which requires some personal information from the user.
When the user presses the "OK" button, he is send to another activity
Pressing the "Send" button the user is send back to the first activity
TextViews (and other GUI components) can be hidden (fragment from main.xml)
<TextView android:id="@+id/textViewName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone" />And made visible on your command (Java code fragment)
final TextView addressView = findViewById(R.id.textViewAddress); addressView.setVisibility(View.VISIBLE);
Code fragments from secondary activity: putting the data into the returning intent
public static final String NAME = "name"; ... Intent data = new Intent(); EditText nameField = findViewById(R.id.name); data.putExtra(NAME, nameField.getText().toString());
Code fragment from main activity: reading the data
String name = data.getStringExtra(PersonalInfoActivity.NAME); nameView.setText("Name: " + name);
Try to make the child activity look like a dialog.
Open the Manifest file and add an attribute to the <activity ...> element
<activity android:name=".PersonalInfoActivity" android:theme="@android:style/Theme.Dialog"> </activity>Make sure your activity extends the class Activity directly, not some subclass of Activity, like AppCo...Activity.