`
MainActivity
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="@color/colorAccent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_marginTop="30dp"
android:textStyle="bold"
android:textColor="#fff"
android:id="@+id/textView"
android:textSize="22sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="What is your name?" />
<EditText
android:id="@+id/name"
android:layout_width="250dp"
android:layout_height="wrap_content" />
<Button
android:id="@+id/btn1"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="Next"
android:layout_marginTop="200dp"
android:layout_gravity="center_horizontal"/>
<Button
android:id="@+id/btnSummary"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="Open Summary"
android:layout_marginTop="200dp"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
// SecondActitvity
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:background="#8E44AD"
android:orientation="vertical"
tools:context=".SecondActivity">
<TextView
android:layout_marginTop="30dp"
android:textStyle="bold"
android:textColor="#fff"
android:id="@+id/textView"
android:textSize="22sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Who is the best cricketer in the world?" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="80dp">
<RadioGroup
android:id="@+id/options"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RadioButton
android:id="@+id/jacques"
android:paddingLeft="15dp"
android:textColor="#fff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Jacques Kallis"
android:textSize="22sp"/>
<RadioButton
android:id="@+id/adnan"
android:paddingLeft="15dp"
android:textColor="#fff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Adnan"
android:textSize="22sp"/>
<RadioButton
android:id="@+id/sachine"
android:paddingLeft="15dp"
android:textColor="#fff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sachine Tendulkar"
android:textSize="22sp"/>
<RadioButton
android:id="@+id/virat"
android:paddingLeft="15dp"
android:textColor="#fff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Virat"
android:textSize="22sp"/>
</RadioGroup>
</LinearLayout>
<Button
android:id="@+id/btn2"
android:layout_width="250dp"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_marginTop="150dp"
android:background="#ECF0F1"
android:text="Next"
/>
</LinearLayout>
//ThirdActivity
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#7845"
tools:context=".ThirdActivity">
<TextView
android:layout_marginTop="30dp"
android:textStyle="bold"
android:id="@+id/textView"
android:textSize="22sp"
android:textColor="#fff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="What are the colors in indian national flag?" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#fff"
android:layout_marginTop="10dp"
android:text="Options:"
android:textStyle="bold"
android:textSize="22sp"
android:paddingLeft="10dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:orientation="vertical">
<CheckBox
android:id="@+id/checkBox"
android:padding="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:textColor="#fff"
android:textSize="22sp"
android:text="White" />
<CheckBox
android:id="@+id/checkBox2"
android:padding="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#fff"
android:textSize="22sp"
android:text="Orage" />
<CheckBox
android:textSize="22sp"
android:padding="5dp"
android:id="@+id/checkBox3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#fff"
android:text="Green" />
<CheckBox
android:textSize="22sp"
android:padding="5dp"
android:id="@+id/checkBox4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#fff"
android:text="Yellow" />
<Button
android:id="@+id/btn3"
android:layout_width="250dp"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_marginTop="150dp"
android:background="#ECF0F1"
android:text="Next"
/>
</LinearLayout>
</LinearLayout>
//SummaryActivity
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="@color/colorAccent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textMsg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textSize="22sp"
android:textColor="#fff"
android:textStyle="bold"
android:layout_marginTop="30dp"
android:layout_marginLeft="20dp"/>
</LinearLayout>
//MainActivity.java
public class MainActivity extends AppCompatActivity {
Button button;
TextView tv;
EditText editText;
Context context;
Button buttonSummary;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv=findViewById(R.id.textMsg);
editText = findViewById(R.id.name);
button = findViewById(R.id.btn1);
buttonSummary = findViewById(R.id.btnSummary);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(getApplicationContext(), SecondActivity.class));
}
});
buttonSummary.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openSummaryActivity();
}
});
}
public void openSummaryActivity() {
String text = editText.getText().toString();
Intent intent = new Intent(getApplicationContext(), SummaryActivity.class);
intent.putExtra("KEY", text);
startActivity(intent);
}}
SummaryActivity.java
public class SummaryActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_summary);
Intent intent = getIntent();
String text = intent.getStringExtra("KEY");
TextView textView = (TextView) findViewById(R.id.textMsg);
textView.setText(text);
}
}
`I have 4 activities.First activity with input text.
Second activity with selecting best cricketer, used radio buttons.
Third activity selecting options used checkbox.
In fourth activity I need to display everything from activity 1 2 3's selected data in 4th activity.
SUMMARY
Hello “Name:” ,
Here are the answers selected:
Who is the best cricketer in the world?
Answer: “ “
What are the colors in the national flag?
Answers : “Commo separated”