You are on page 1of 5

Registration form

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
// These are the global variables
EditText editName, editPassword,editAddress,editAge;
TextView result;
RadioGroup radioGroup;
RadioButton radioButton;
Button buttonSubmit;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editName = (EditText) findViewById(R.id.uname);
editPassword = (EditText) findViewById(R.id.pass);
editAddress = (EditText) findViewById(R.id.add);
editAge = (EditText) findViewById(R.id.age);
radioGroup = (RadioGroup) findViewById(R.id.radioGender);
result = (TextView) findViewById(R.id.res);
buttonSubmit = (Button) findViewById(R.id.btn);
buttonSubmit.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
String name = editName.getText().toString();
String password = editPassword.getText().toString();
String address= editAddress.getText().toString();
String age= editAge.getText().toString();
int selectedId = radioGroup.getCheckedRadioButtonId();
// find the radiobutton by returned id
radioButton = (RadioButton) findViewById(selectedId);
result.setText("Name:\t" + name + "\nPassword:\t" +
password+ "\nAddredd:\t" +
address+ "\nAGE:\t" + age+ "\nGender:\t" +
radioButton.getText());

}
});

}
}
xml file

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Registration Form"></TextView>
<EditText
android:id="@+id/uname"
android:hint="Username"
android:textSize="18sp"
android:layout_margin="10dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/pass"
android:hint="Password"
android:textSize="18sp"
android:layout_margin="10dp"
android:inputType="textPassword"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<EditText
android:id="@+id/add"
android:layout_width="match_parent"
android:textSize="18sp"
android:layout_margin="10dp"
android:hint="Address"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/age"
android:textSize="18sp"
android:layout_margin="10dp"
android:hint="Age"
android:inputType="number"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_height="wrap_content" />
<LinearLayout
android:gravity="center_horizontal"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<RadioGroup
android:id="@+id/radioGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/radioMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/radiomale"
android:checked="true" />
<RadioButton
android:id="@+id/radioFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/radiofemale" />
</RadioGroup>

</LinearLayout>
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Submit"></Button>
<TextView
android:id="@+id/res"
android:layout_width="match_parent"
android:layout_height="wrap_content"></TextView>
</LinearLayout>

In res/values/strings.xml
Add this
<resources>
<string name="radiomale">Male</string>
<string name="radiofemale">Female</string>
</resources>

Linear layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:gravity="center_horizontal"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="Row 1 Col 1"
android:textSize="18sp"
android:layout_margin="10dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="Row 1 Col 2"
android:textSize="18sp"
android:layout_margin="10dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</LinearLayout>
<TextView
android:text="Row 2"
android:layout_width="match_parent"
android:textSize="18sp"
android:layout_margin="10dp"
android:layout_height="wrap_content" />
<TextView
android:text="Row 3"
android:textSize="18sp"
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:text="Row 4"
android:textSize="18sp"
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</LinearLayout>

Relative Layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp" >

<EditText
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Name" />

<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentStart="true"
android:layout_below="@+id/name">

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button2" />

</LinearLayout>

</RelativeLayout>
Table Layout

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<TableRow>

<TextView
android:text="Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1" />

<EditText
android:width="200px"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>

<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ratingBar"
android:layout_column="2" />
</TableRow>

<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:id="@+id/button"
android:layout_column="2" />
</TableRow>

</TableLayout>

Grid view :

https://www.geeksforgeeks.org/gridview-in-android-with-example/

You might also like