Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

Name : Adityarajsinh Chauhan

Enrollment No : 200305105117

MainActivity :
package com.example.form;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import java.util.Objects;

public class MainActivity extends AppCompatActivity {


TextView
nametext,emailtext,agetext,passwordtext,gendertext,citytext;
EditText name,email,age,password;
Spinner sp;
Button submit;
String s_name,s_email,s_age,s_password,s_gender,s_city;
RadioButton male,female;
String val = "";
@Override
protected void onCreate(Bundle savedInstanceState) {

Objects.requireNonNull(getSupportActionBar()).setTitle("Adityarajsin
h Chauhan 200305105117");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
nametext = findViewById(R.id.name_text);
emailtext = findViewById(R.id.email_text);
agetext = findViewById(R.id.age_text);
passwordtext = findViewById(R.id.password_text);
gendertext = findViewById(R.id.gender_text);
citytext = findViewById(R.id.city_text);

name = findViewById(R.id.name);
email = findViewById(R.id.email);
age = findViewById(R.id.age);
password = findViewById(R.id.password);
submit = findViewById(R.id.submit);
sp = findViewById(R.id.city);
male=findViewById(R.id.male);
female=findViewById(R.id.female);

RadioGroup radioGroup = findViewById(R.id.gender);

ArrayAdapter<CharSequence> adapter =
ArrayAdapter.createFromResource(this,R.array.cities,
android.R.layout.simple_spinner_item);

adapter.setDropDownViewResource(android.R.layout.simple_spinne
r_dropdown_item);
sp.setAdapter(adapter);
sp.setOnItemSelectedListener(new
AdapterView.OnItemSelectedListener() {

@Override
public void onItemSelected(AdapterView<?> parent, View
view, int position, long id) {
val = parent.getItemAtPosition(position).toString();
Toast.makeText(parent.getContext(), val,
Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {

}
});
submit.setOnClickListener(v -> {

String gender ="";


int checkedButton = radioGroup.getCheckedRadioButtonId();
if(checkedButton==R.id.male){
gender = "Male";
}
else if(checkedButton==R.id.female){
gender = "Female";
}

s_name = name.getText().toString().trim();
s_email = email.getText().toString().trim();
s_age = age.getText().toString().trim();
s_password = password.getText().toString().trim();
s_gender = gender;
s_city = val;

Intent intent = new Intent(MainActivity.this,Activity2.class);


intent.putExtra(Activity2.NAME,s_name);
intent.putExtra(Activity2.EMAIL,s_email);
intent.putExtra(Activity2.AGE,s_age);
intent.putExtra(Activity2.PASSWORD,s_password);
intent.putExtra(Activity2.GENDER,s_gender);
intent.putExtra(Activity2.CITY,s_city);

startActivity(intent);
});
}
}

Activity2 :

package com.example.form;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

public class Activity2 extends AppCompatActivity {


public static final String NAME = "NAME";
public static final String EMAIL = "EMAIL";
public static final String AGE = "AGE";
public static final String PASSWORD = "PASSWORD";
public static final String GENDER = "GENDER";
public static final String CITY = "CITY";

TextView
name_text1,email_text1,age_text1,password_text1,gender_text1,cit
y_text1;

String name2,email2,age2,password2,gender2,city2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_2);

name_text1 = findViewById(R.id.nametext1);
email_text1 = findViewById(R.id.emailtext1);
age_text1 = findViewById(R.id.agetext1);
password_text1 = findViewById(R.id.passwordtext1);
gender_text1 = findViewById(R.id.gendertext1);
city_text1 = findViewById(R.id.citytext1);
Intent intent = getIntent();

name2 = intent.getStringExtra(NAME);
email2 = intent.getStringExtra(EMAIL);
age2 = intent.getStringExtra(AGE);
password2 = intent.getStringExtra(PASSWORD);
gender2 = intent.getStringExtra(GENDER);
city2 = intent.getStringExtra(CITY);

name_text1.setText(name2);
email_text1.setText(email2);
age_text1.setText(age2);
password_text1.setText(password2);
gender_text1.setText(gender2);
city_text1.setText(city2);

}
}

activity_main.xml :

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Form"
android:textSize="50sp"
android:layout_marginStart="15sp"
android:layout_marginTop="10sp"
android:textStyle="bold"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10sp">
<TextView
android:id="@+id/name_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name :"
android:layout_marginStart="15sp"
android:textSize="25sp"/>
<EditText
android:id="@+id/name"
android:layout_width="300sp"
android:layout_height="wrap_content"
android:inputType="textPersonName"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10sp">
<TextView
android:id="@+id/email_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email :"
android:layout_marginStart="15sp"
android:textSize="25sp"/>

<EditText
android:id="@+id/email"
android:layout_width="310sp"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10sp">
<TextView
android:id="@+id/age_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Age :"
android:layout_marginStart="15sp"
android:textSize="25sp"/>

<EditText
android:id="@+id/age"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:inputType="number"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10sp">
<TextView
android:id="@+id/password_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password :"
android:layout_marginStart="15sp"
android:textSize="25sp" />

<EditText
android:id="@+id/password"
android:layout_width="250sp"
android:layout_height="wrap_content"
android:inputType="textPassword"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10sp">
<TextView
android:id="@+id/gender_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gender :"
android:layout_marginStart="15sp"
android:textSize="25sp" />
<RadioGroup
android:id="@+id/gender"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:textSize="25sp"/>
<RadioButton
android:id="@+id/female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:textSize="25sp"
android:layout_marginStart="10sp"/>

</RadioGroup>
</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10sp">
<TextView
android:id="@+id/city_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="City :"
android:layout_marginStart="15sp"
android:textSize="25sp"/>
<Spinner
android:id="@+id/city"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="35sp"/>
</LinearLayout>
<Button
android:id="@+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:textSize="25sp"
android:textAlignment="center"
android:layout_marginTop="20sp"
android:layout_marginStart="120sp"/>

</LinearLayout>

activity_2.xml :

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/nametext1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name"
android:textSize="40sp"
android:layout_margin="10sp"/>
<TextView
android:id="@+id/emailtext1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Email"
android:textSize="40sp"
android:layout_margin="10sp"/>
<TextView
android:id="@+id/agetext1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Age"
android:textSize="40sp"
android:layout_margin="10sp"/>
<TextView
android:id="@+id/passwordtext1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Password"
android:textSize="40sp"
android:layout_margin="10sp"/>
<TextView
android:id="@+id/gendertext1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Gender"
android:textSize="40sp"
android:layout_margin="10sp"/>
<TextView
android:id="@+id/citytext1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="City"
android:textSize="40sp"
android:layout_margin="10sp"/>
</LinearLayout>

Output :

You might also like