Advertisement
angeloeboy10

Untitled

Feb 12th, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.80 KB | None | 0 0
  1. sa MainAcvtivity ito
  2.  
  3. import android.app.DatePickerDialog;
  4. import android.content.Intent;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.os.Bundle;
  7. import android.view.View;
  8. import android.widget.Button;
  9. import android.widget.DatePicker;
  10. import android.widget.EditText;
  11. import android.widget.RadioButton;
  12. import android.widget.RadioGroup;
  13. import android.widget.TextView;
  14. import android.widget.Toast;
  15.  
  16. import java.util.Calendar;
  17.  
  18. public class MainActivity extends AppCompatActivity {
  19.  
  20.  
  21.     String firstName,middleName, lastName, fullName, gender, birthday;
  22.     int year, month, dayOfMonth;
  23.     RadioGroup radioGenderGroup;
  24.     RadioButton radioGenderButton;
  25.     Button datePick;
  26.     DatePickerDialog datePickerDialog;
  27.  
  28.     @Override
  29.     protected void onCreate(Bundle savedInstanceState) {
  30.         super.onCreate(savedInstanceState);
  31.         setContentView(R.layout.activity_main);
  32.  
  33.         Button submitButton = (Button)findViewById(R.id.submit);
  34.         radioGenderGroup = (RadioGroup)findViewById(R.id.radioGenderGroup);
  35.  
  36.         datePick = findViewById(R.id.datePicker);
  37.  
  38.         datePick.setOnClickListener(new View.OnClickListener() {
  39.             @Override
  40.             public void onClick(View view) {
  41.  
  42.                 Calendar calendar = Calendar.getInstance();
  43.                 int year = calendar.get(Calendar.YEAR);
  44.                 int month = calendar.get(Calendar.MONTH);
  45.                 int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
  46.  
  47.                 datePickerDialog = new DatePickerDialog(MainActivity.this,
  48.                         new DatePickerDialog.OnDateSetListener() {
  49.                             @Override
  50.                             public void onDateSet(DatePicker datePicker, int year, int month, int day) {
  51.                                 birthday = day + "/" + (month + 1) + "/" + year;
  52.                                 Toast.makeText(MainActivity.this, birthday, Toast.LENGTH_SHORT).show();
  53.                             }
  54.                         }, year, month, dayOfMonth);
  55.                 datePickerDialog.show();
  56.             }
  57.         });
  58.  
  59.  
  60.         //When the submit button is clicked
  61.         submitButton.setOnClickListener(new View.OnClickListener() {
  62.             @Override
  63.             public void onClick(View view) {
  64.  
  65.                 //Kinuha yung data from editText
  66.                 EditText first = (EditText)findViewById(R.id.firstName);
  67.                 EditText middle = (EditText)findViewById(R.id.middleName);
  68.                 EditText last = (EditText)findViewById(R.id.lastName);
  69.  
  70.                 //converted the data into strings
  71.                 firstName = first.getText().toString();
  72.                 middleName = middle.getText().toString();
  73.                 lastName = last.getText().toString();
  74.  
  75.                 //dito pinagsamasama to get the full name
  76.                 fullName = firstName + " " + middleName + " " + lastName;
  77.  
  78.                 int selectedId = radioGenderGroup.getCheckedRadioButtonId();
  79.  
  80.                 radioGenderButton = (RadioButton) findViewById(selectedId);
  81.  
  82.                 gender = (String)radioGenderButton.getText();
  83.  
  84.  
  85.                 Intent intent = new Intent(MainActivity.this, studentInfo.class);
  86.  
  87.                 //passing the data from this to another activity by intent
  88.                 intent.putExtra("FullName", fullName);
  89.                 intent.putExtra("Gender", gender);
  90.                 intent.putExtra("Birthday", birthday);
  91.  
  92.                 startActivity(intent);
  93.  
  94.             }
  95.         });
  96.  
  97.  
  98.     }
  99. }
  100.  
  101. yung xml file
  102. <?xml version="1.0" encoding="utf-8"?>
  103. <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  104.     xmlns:app="http://schemas.android.com/apk/res-auto"
  105.     xmlns:tools="http://schemas.android.com/tools"
  106.     android:layout_width="match_parent"
  107.     android:layout_height="match_parent"
  108.     tools:context=".MainActivity">
  109.  
  110.     <EditText
  111.         android:id="@+id/firstName"
  112.         android:layout_width="363dp"
  113.         android:layout_height="wrap_content"
  114.         android:layout_marginStart="8dp"
  115.         android:layout_marginTop="24dp"
  116.         android:layout_marginEnd="8dp"
  117.         android:layout_marginBottom="678dp"
  118.         android:ems="10"
  119.         android:hint="First Name"
  120.         android:inputType="textPersonName"
  121.         app:layout_constraintBottom_toBottomOf="parent"
  122.         app:layout_constraintEnd_toEndOf="parent"
  123.         app:layout_constraintStart_toStartOf="parent"
  124.         app:layout_constraintTop_toTopOf="parent"
  125.         app:layout_constraintVertical_bias="0.0" />
  126.  
  127.     <EditText
  128.         android:id="@+id/middleName"
  129.         android:layout_width="364dp"
  130.         android:layout_height="wrap_content"
  131.         android:layout_marginStart="8dp"
  132.         android:layout_marginTop="28dp"
  133.         android:layout_marginEnd="8dp"
  134.         android:layout_marginBottom="26dp"
  135.         android:ems="10"
  136.         android:hint="Middle Name"
  137.         android:inputType="textPersonName"
  138.         app:layout_constraintBottom_toTopOf="@+id/lastName"
  139.         app:layout_constraintEnd_toEndOf="parent"
  140.         app:layout_constraintHorizontal_bias="0.483"
  141.         app:layout_constraintStart_toStartOf="parent"
  142.         app:layout_constraintTop_toBottomOf="@+id/firstName" />
  143.  
  144.     <EditText
  145.         android:id="@+id/lastName"
  146.         android:layout_width="360dp"
  147.         android:layout_height="wrap_content"
  148.         android:layout_marginStart="8dp"
  149.         android:layout_marginTop="26dp"
  150.         android:layout_marginEnd="8dp"
  151.         android:ems="10"
  152.         android:hint="Last Name"
  153.         android:inputType="textPersonName"
  154.         app:layout_constraintEnd_toEndOf="parent"
  155.         app:layout_constraintStart_toStartOf="parent"
  156.         app:layout_constraintTop_toBottomOf="@+id/middleName" />
  157.  
  158.     <TextView
  159.         android:id="@+id/Gender"
  160.         android:layout_width="wrap_content"
  161.         android:layout_height="wrap_content"
  162.         android:layout_marginStart="8dp"
  163.         android:layout_marginTop="120dp"
  164.         android:layout_marginEnd="8dp"
  165.         android:text="Gender"
  166.         app:layout_constraintEnd_toEndOf="parent"
  167.         app:layout_constraintHorizontal_bias="0.053"
  168.         app:layout_constraintStart_toStartOf="parent"
  169.         app:layout_constraintTop_toTopOf="@+id/lastName" />
  170.  
  171.     <RadioGroup
  172.         android:id="@+id/radioGenderGroup"
  173.         android:layout_width="wrap_content"
  174.         android:layout_height="64dp"
  175.         android:layout_marginStart="8dp"
  176.         android:layout_marginTop="26dp"
  177.         android:layout_marginEnd="8dp"
  178.         app:layout_constraintEnd_toEndOf="parent"
  179.         app:layout_constraintHorizontal_bias="0.05"
  180.         app:layout_constraintStart_toStartOf="parent"
  181.         app:layout_constraintTop_toBottomOf="@+id/Gender">
  182.  
  183.         <RadioButton
  184.             android:id="@+id/radioMale"
  185.             android:layout_width="wrap_content"
  186.             android:layout_height="wrap_content"
  187.             android:text="@string/radio_male" />
  188.  
  189.         <RadioButton
  190.             android:id="@+id/radioFemale"
  191.             android:layout_width="wrap_content"
  192.             android:layout_height="wrap_content"
  193.             android:text="@string/radio_female" />
  194.  
  195.     </RadioGroup>
  196.  
  197.     <Button
  198.         android:id="@+id/submit"
  199.         android:layout_width="wrap_content"
  200.         android:layout_height="wrap_content"
  201.         android:layout_marginStart="8dp"
  202.         android:layout_marginEnd="8dp"
  203.         android:layout_marginBottom="48dp"
  204.         android:text="Submit"
  205.         app:layout_constraintBottom_toBottomOf="parent"
  206.         app:layout_constraintEnd_toEndOf="parent"
  207.         app:layout_constraintHorizontal_bias="0.498"
  208.         app:layout_constraintStart_toStartOf="parent" />
  209.  
  210.     <TextView
  211.         android:id="@+id/birthday"
  212.         android:layout_width="wrap_content"
  213.         android:layout_height="wrap_content"
  214.         android:layout_marginStart="8dp"
  215.         android:layout_marginTop="72dp"
  216.         android:layout_marginEnd="8dp"
  217.         android:text="Birthday"
  218.         app:layout_constraintEnd_toEndOf="parent"
  219.         app:layout_constraintHorizontal_bias="0.795"
  220.         app:layout_constraintStart_toEndOf="@+id/Gender"
  221.         app:layout_constraintTop_toBottomOf="@+id/lastName" />
  222.  
  223.     <Button
  224.         android:id="@+id/datePicker"
  225.         android:layout_width="wrap_content"
  226.         android:layout_height="43dp"
  227.         android:layout_marginStart="243dp"
  228.         android:layout_marginTop="20dp"
  229.         android:layout_marginEnd="32dp"
  230.         android:onClick="datePicker"
  231.         android:text="Select Date"
  232.         app:layout_constraintEnd_toEndOf="parent"
  233.         app:layout_constraintStart_toStartOf="@+id/radioGenderGroup"
  234.         app:layout_constraintTop_toBottomOf="@+id/birthday" />
  235.  
  236.  
  237. </android.support.constraint.ConstraintLayout>
  238.  
  239.  
  240.  
  241.  
  242.  
  243. Sa activity na pagsesendan
  244.  
  245. package com.example.login;
  246.  
  247. import android.support.v7.app.AppCompatActivity;
  248. import android.os.Bundle;
  249. import android.widget.TextView;
  250.  
  251. import org.w3c.dom.Text;
  252.  
  253. public class studentInfo extends AppCompatActivity {
  254.  
  255.     TextView fullNameContainer, genderContainer, birthdayContainer;
  256.  
  257.     @Override
  258.     protected void onCreate(Bundle savedInstanceState) {
  259.         super.onCreate(savedInstanceState);
  260.         setContentView(R.layout.activity_student_info);
  261.  
  262.         fullNameContainer = (TextView)findViewById(R.id.fullName);
  263.         genderContainer = (TextView)findViewById(R.id.gender);
  264.         birthdayContainer = (TextView)findViewById(R.id.birthday);
  265.  
  266.         fullNameContainer.setText("Full Name: " + getIntent().getStringExtra("FullName"));
  267.         genderContainer.setText("Gender: " + getIntent().getStringExtra("Gender"));
  268.         birthdayContainer.setText("Date Of Birth: " + getIntent().getStringExtra("Birthday"));
  269.  
  270.  
  271.     }
  272. }
  273.  
  274. yung xml file
  275. <?xml version="1.0" encoding="utf-8"?>
  276. <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  277.     xmlns:app="http://schemas.android.com/apk/res-auto"
  278.     xmlns:tools="http://schemas.android.com/tools"
  279.     android:layout_width="match_parent"
  280.     android:layout_height="match_parent"
  281.     tools:context=".studentInfo">
  282.  
  283.     <TextView
  284.         android:id="@+id/fullName"
  285.         android:layout_width="wrap_content"
  286.         android:layout_height="28dp"
  287.         android:layout_marginStart="94dp"
  288.         android:layout_marginTop="140dp"
  289.         android:layout_marginEnd="224dp"
  290.         android:text="Full Name: "
  291.         android:textSize="18sp"
  292.         app:layout_constraintEnd_toEndOf="parent"
  293.         app:layout_constraintStart_toStartOf="parent"
  294.         app:layout_constraintTop_toTopOf="parent" />
  295.  
  296.     <TextView
  297.         android:id="@+id/gender"
  298.         android:layout_width="wrap_content"
  299.         android:layout_height="wrap_content"
  300.         android:layout_marginStart="94dp"
  301.         android:layout_marginTop="40dp"
  302.         android:layout_marginEnd="252dp"
  303.         android:layout_marginBottom="523dp"
  304.         android:text="Gender: "
  305.         android:textSize="18sp"
  306.         app:layout_constraintBottom_toBottomOf="parent"
  307.         app:layout_constraintEnd_toEndOf="parent"
  308.         app:layout_constraintStart_toStartOf="parent"
  309.         app:layout_constraintTop_toBottomOf="@+id/fullName"
  310.         app:layout_constraintVertical_bias="0.0" />
  311.  
  312.     <TextView
  313.         android:id="@+id/birthday"
  314.         android:layout_width="wrap_content"
  315.         android:layout_height="wrap_content"
  316.         android:layout_marginStart="94dp"
  317.         android:layout_marginTop="44dp"
  318.         android:layout_marginEnd="248dp"
  319.         android:text="Birthday:"
  320.         android:textSize="18sp"
  321.         app:layout_constraintEnd_toEndOf="parent"
  322.         app:layout_constraintStart_toStartOf="parent"
  323.         app:layout_constraintTop_toBottomOf="@+id/gender" />
  324.  
  325. </android.support.constraint.ConstraintLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement