Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sa MainAcvtivity ito
- import android.app.DatePickerDialog;
- import android.content.Intent;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.DatePicker;
- import android.widget.EditText;
- import android.widget.RadioButton;
- import android.widget.RadioGroup;
- import android.widget.TextView;
- import android.widget.Toast;
- import java.util.Calendar;
- public class MainActivity extends AppCompatActivity {
- String firstName,middleName, lastName, fullName, gender, birthday;
- int year, month, dayOfMonth;
- RadioGroup radioGenderGroup;
- RadioButton radioGenderButton;
- Button datePick;
- DatePickerDialog datePickerDialog;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- Button submitButton = (Button)findViewById(R.id.submit);
- radioGenderGroup = (RadioGroup)findViewById(R.id.radioGenderGroup);
- datePick = findViewById(R.id.datePicker);
- datePick.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Calendar calendar = Calendar.getInstance();
- int year = calendar.get(Calendar.YEAR);
- int month = calendar.get(Calendar.MONTH);
- int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
- datePickerDialog = new DatePickerDialog(MainActivity.this,
- new DatePickerDialog.OnDateSetListener() {
- @Override
- public void onDateSet(DatePicker datePicker, int year, int month, int day) {
- birthday = day + "/" + (month + 1) + "/" + year;
- Toast.makeText(MainActivity.this, birthday, Toast.LENGTH_SHORT).show();
- }
- }, year, month, dayOfMonth);
- datePickerDialog.show();
- }
- });
- //When the submit button is clicked
- submitButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- //Kinuha yung data from editText
- EditText first = (EditText)findViewById(R.id.firstName);
- EditText middle = (EditText)findViewById(R.id.middleName);
- EditText last = (EditText)findViewById(R.id.lastName);
- //converted the data into strings
- firstName = first.getText().toString();
- middleName = middle.getText().toString();
- lastName = last.getText().toString();
- //dito pinagsamasama to get the full name
- fullName = firstName + " " + middleName + " " + lastName;
- int selectedId = radioGenderGroup.getCheckedRadioButtonId();
- radioGenderButton = (RadioButton) findViewById(selectedId);
- gender = (String)radioGenderButton.getText();
- Intent intent = new Intent(MainActivity.this, studentInfo.class);
- //passing the data from this to another activity by intent
- intent.putExtra("FullName", fullName);
- intent.putExtra("Gender", gender);
- intent.putExtra("Birthday", birthday);
- startActivity(intent);
- }
- });
- }
- }
- yung xml file
- <?xml version="1.0" encoding="utf-8"?>
- <android.support.constraint.ConstraintLayout 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"
- tools:context=".MainActivity">
- <EditText
- android:id="@+id/firstName"
- android:layout_width="363dp"
- android:layout_height="wrap_content"
- android:layout_marginStart="8dp"
- android:layout_marginTop="24dp"
- android:layout_marginEnd="8dp"
- android:layout_marginBottom="678dp"
- android:ems="10"
- android:hint="First Name"
- android:inputType="textPersonName"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent"
- app:layout_constraintVertical_bias="0.0" />
- <EditText
- android:id="@+id/middleName"
- android:layout_width="364dp"
- android:layout_height="wrap_content"
- android:layout_marginStart="8dp"
- android:layout_marginTop="28dp"
- android:layout_marginEnd="8dp"
- android:layout_marginBottom="26dp"
- android:ems="10"
- android:hint="Middle Name"
- android:inputType="textPersonName"
- app:layout_constraintBottom_toTopOf="@+id/lastName"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintHorizontal_bias="0.483"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/firstName" />
- <EditText
- android:id="@+id/lastName"
- android:layout_width="360dp"
- android:layout_height="wrap_content"
- android:layout_marginStart="8dp"
- android:layout_marginTop="26dp"
- android:layout_marginEnd="8dp"
- android:ems="10"
- android:hint="Last Name"
- android:inputType="textPersonName"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/middleName" />
- <TextView
- android:id="@+id/Gender"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginStart="8dp"
- android:layout_marginTop="120dp"
- android:layout_marginEnd="8dp"
- android:text="Gender"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintHorizontal_bias="0.053"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="@+id/lastName" />
- <RadioGroup
- android:id="@+id/radioGenderGroup"
- android:layout_width="wrap_content"
- android:layout_height="64dp"
- android:layout_marginStart="8dp"
- android:layout_marginTop="26dp"
- android:layout_marginEnd="8dp"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintHorizontal_bias="0.05"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/Gender">
- <RadioButton
- android:id="@+id/radioMale"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/radio_male" />
- <RadioButton
- android:id="@+id/radioFemale"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/radio_female" />
- </RadioGroup>
- <Button
- android:id="@+id/submit"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginStart="8dp"
- android:layout_marginEnd="8dp"
- android:layout_marginBottom="48dp"
- android:text="Submit"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintHorizontal_bias="0.498"
- app:layout_constraintStart_toStartOf="parent" />
- <TextView
- android:id="@+id/birthday"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginStart="8dp"
- android:layout_marginTop="72dp"
- android:layout_marginEnd="8dp"
- android:text="Birthday"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintHorizontal_bias="0.795"
- app:layout_constraintStart_toEndOf="@+id/Gender"
- app:layout_constraintTop_toBottomOf="@+id/lastName" />
- <Button
- android:id="@+id/datePicker"
- android:layout_width="wrap_content"
- android:layout_height="43dp"
- android:layout_marginStart="243dp"
- android:layout_marginTop="20dp"
- android:layout_marginEnd="32dp"
- android:onClick="datePicker"
- android:text="Select Date"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="@+id/radioGenderGroup"
- app:layout_constraintTop_toBottomOf="@+id/birthday" />
- </android.support.constraint.ConstraintLayout>
- Sa activity na pagsesendan
- package com.example.login;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.widget.TextView;
- import org.w3c.dom.Text;
- public class studentInfo extends AppCompatActivity {
- TextView fullNameContainer, genderContainer, birthdayContainer;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_student_info);
- fullNameContainer = (TextView)findViewById(R.id.fullName);
- genderContainer = (TextView)findViewById(R.id.gender);
- birthdayContainer = (TextView)findViewById(R.id.birthday);
- fullNameContainer.setText("Full Name: " + getIntent().getStringExtra("FullName"));
- genderContainer.setText("Gender: " + getIntent().getStringExtra("Gender"));
- birthdayContainer.setText("Date Of Birth: " + getIntent().getStringExtra("Birthday"));
- }
- }
- yung xml file
- <?xml version="1.0" encoding="utf-8"?>
- <android.support.constraint.ConstraintLayout 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"
- tools:context=".studentInfo">
- <TextView
- android:id="@+id/fullName"
- android:layout_width="wrap_content"
- android:layout_height="28dp"
- android:layout_marginStart="94dp"
- android:layout_marginTop="140dp"
- android:layout_marginEnd="224dp"
- android:text="Full Name: "
- android:textSize="18sp"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent" />
- <TextView
- android:id="@+id/gender"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginStart="94dp"
- android:layout_marginTop="40dp"
- android:layout_marginEnd="252dp"
- android:layout_marginBottom="523dp"
- android:text="Gender: "
- android:textSize="18sp"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/fullName"
- app:layout_constraintVertical_bias="0.0" />
- <TextView
- android:id="@+id/birthday"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginStart="94dp"
- android:layout_marginTop="44dp"
- android:layout_marginEnd="248dp"
- android:text="Birthday:"
- android:textSize="18sp"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/gender" />
- </android.support.constraint.ConstraintLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement