Application like this;
package com.example.registrationform;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
public class MainActivity extends Activity {
EditText edt_user;
EditText edt_pass;
EditText edt_confirm;
EditText edt_email;
RadioButton rb;
RadioGroup rbg;
CheckBox chb_play;
CheckBox chb_cook;
CheckBox chb_draw;
Button btn_submit;
String user_name;
String rb_str;
String pass;
String conf;
String email;
String emailPattern = "[a-zA-z0-9._-]+@[a-z]+\\.+[a-z]+";
String hobbies;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edt_user = (EditText) findViewById(R.id.edt_username);
edt_pass = (EditText) findViewById(R.id.edt_password);
edt_email = (EditText) findViewById(R.id.edt_email);
edt_confirm = (EditText) findViewById(R.id.edt_confirmpass);
chb_play = (CheckBox) findViewById(R.id.chk_playing);
chb_cook = (CheckBox) findViewById(R.id.chk_cooking);
chb_draw = (CheckBox) findViewById(R.id.chk_drawing);
rbg = (RadioGroup) findViewById(R.id.rg_gender);
btn_submit = (Button) findViewById(R.id.btn_submit);
btn_submit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
user_name = edt_user.getText().toString();
pass = edt_pass.getText().toString();
conf = edt_confirm.getText().toString();
email = edt_email.getText().toString();
if (pass.equals(conf)) {
if (email.matches(emailPattern)) {
int idrb = rbg.getCheckedRadioButtonId();
rb = (RadioButton) findViewById(idrb);
rb_str = rb.getText().toString();
if (chb_play.isChecked()) {
String str_play = chb_play.getText().toString();
hobbies = str_play + ",";
}
if (chb_cook.isChecked()) {
String str_cook = chb_cook.getText().toString();
hobbies = hobbies + str_cook + ",";
}
if (chb_draw.isChecked()) {
String str_draw = chb_draw.getText().toString();
hobbies = hobbies + str_draw;
}
Intent in = new Intent(MainActivity.this,
SecondActivity.class);
in.putExtra("user", user_name);
in.putExtra("email", email);
in.putExtra("radio", rb_str);
in.putExtra("hobbies", hobbies);
startActivity(in);
} else {
Toast.makeText(getApplicationContext(),
"Invalid Email Address.", Toast.LENGTH_LONG)
.show();
}
} else {
Toast.makeText(getApplicationContext(),
"Password Mismatch.", Toast.LENGTH_LONG).show();
}
}
});
}
}
Your DisplayActivity like this;
package com.example.registrationform;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.widget.TextView;
public class SecondActivity extends Activity {
TextView txt_user;
TextView txt_email;
TextView txt_gender;
TextView txt_hobbies;
Intent getin;
String username;
String email;
String gender;
String hobbies;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
txt_user = (TextView) findViewById(R.id.txt_uname);
txt_email = (TextView) findViewById(R.id.txt_email);
txt_gender = (TextView) findViewById(R.id.txt_gender);
txt_hobbies = (TextView) findViewById(R.id.txt_hobbies);
getin = getIntent();
username = getin.getStringExtra("user");
email = getin.getStringExtra("email");
gender = getin.getStringExtra("radio");
hobbies = getin.getStringExtra("hobbies");
txt_user.setText(username);
txt_email.setText(email);
txt_gender.setText(gender);
txt_hobbies.setText(hobbies);
}
}
Your activity_main.xml like this;
<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="horizontal"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal" >
<TextView
android:id="@+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="REGISTRATION FORM" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/txt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username" />
<EditText
android:id="@+id/edt_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/txt3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password" />
<EditText
android:id="@+id/edt_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/txt4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Confirm Password" />
<EditText
android:id="@+id/edt_confirmpass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/txt5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="E-MAIL" />
<EditText
android:id="@+id/edt_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textEmailAddress" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioGroup
android:id="@+id/rg_gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/txt_gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GENDER" />
<RadioButton
android:id="@+id/rbt_male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MALE" />
<RadioButton
android:id="@+id/rbt_female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FEMALE" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/txt6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="HOBBIES" />
<CheckBox
android:id="@+id/chk_playing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PLAYING" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="55dp"
android:orientation="vertical" >
<CheckBox
android:id="@+id/chk_cooking"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="COOKING" />
<CheckBox
android:id="@+id/chk_drawing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DRAWING" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Your secondactivity.xml like this;
<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"
tools:context=".SecondActivity" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal" >
<TextView
android:id="@+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Details" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<TextView
android:id="@+id/txt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="USERNAME " />
<TextView
android:id="@+id/txt_uname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="uname" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<TextView
android:id="@+id/txt3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="E-MAIL" />
<TextView
android:id="@+id/txt_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<TextView
android:id="@+id/txt4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gender" />
<TextView
android:id="@+id/txt_gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<TextView
android:id="@+id/txt5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hobbies" />
<TextView
android:id="@+id/txt_hobbies"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>