0% found this document useful (0 votes)
56 views6 pages

Selesaikan Dan Buka Kembali Project Android Studio Minggu Lalu 2. Klik File - New - Activity - Empty Activity

The document provides instructions for creating a new activity called Activity2 in an Android Studio project. It includes code to design the Activity2 user interface with text fields in a scrollview layout. It also includes code for the Activity2 class to retrieve data sent from the MainActivity class and display it in the text fields. The document further includes code for the MainActivity class to collect user input, retrieve the selected gender from radio buttons, and send the data to Activity2 using an intent when a button is clicked.

Uploaded by

Rahmad Rifa'i
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views6 pages

Selesaikan Dan Buka Kembali Project Android Studio Minggu Lalu 2. Klik File - New - Activity - Empty Activity

The document provides instructions for creating a new activity called Activity2 in an Android Studio project. It includes code to design the Activity2 user interface with text fields in a scrollview layout. It also includes code for the Activity2 class to retrieve data sent from the MainActivity class and display it in the text fields. The document further includes code for the MainActivity class to collect user input, retrieve the selected gender from radio buttons, and send the data to Activity2 using an intent when a button is clicked.

Uploaded by

Rahmad Rifa'i
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1.

Selesaikan dan buka kembali project Android Studio minggu lalu


2. Klik File -> New -> Activity -> Empty Activity
3. Beri nama Activity dan Klik Finish

4. Pada Activity_2.xml, tuliskan baris program berikut


<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Activity2"
android:background="@color/colorPrimaryDark">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:padding="20dp"
android:layout_margin="20dp"
android:background="@color/white"
android:orientation="vertical"
>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Summary"
android:textAlignment="center"
android:textSize="20sp"/>

<TextView
android:id="@+id/textFirstName"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="First" />

<TextView
android:id="@+id/textLastName"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Last" />

<TextView
android:id="@+id/textGender"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Gender" />

<TextView
android:id="@+id/textEmail"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Email" />

<TextView
android:id="@+id/textAddress"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Address" />

<TextView
android:id="@+id/textUserName"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Username" />

<TextView
android:id="@+id/textPhoneNumber"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Phone" />

</LinearLayout>
</ScrollView>
5. Pada Activity2.java, tuliskan baris program berikut

import androidx.appcompat.app.AppCompatActivity;

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

public class Activity2 extends AppCompatActivity {


TextView textFirstName, textLastName, textEmail, textAddress,
textPhoneNumber, textUsername, textGender;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_2);
Bundle bundle = getIntent().getExtras();
String firstName = bundle.getString("firstName");
String lastName = bundle.getString("lastName");
String email = bundle.getString("email");
String address = bundle.getString("address");
String phoneNumber = bundle.getString("phoneNumber");
String username = bundle.getString("username");
String gender = bundle.getString("gender");

textFirstName = findViewById(R.id.textFirstName);
textLastName = findViewById(R.id.textLastName);
textEmail = findViewById(R.id.textEmail);
textAddress = findViewById(R.id.textAddress);
textPhoneNumber = findViewById(R.id.textPhoneNumber);
textUsername = findViewById(R.id.textUserName);
textGender = findViewById(R.id.textGender);

//Menampilkan teks
textFirstName.setText(firstName);
textLastName.setText(lastName);
textEmail.setText(email);
textAddress.setText(address);
textPhoneNumber.setText(phoneNumber);
textUsername.setText(username);
textGender.setText(gender);

}
}
6. Pada MainActivity.java, tuliskan baris program berikut

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
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 org.w3c.dom.Text;

public class MainActivity extends AppCompatActivity {

Button button;//Variabel untuk tombol

//Variabel String
String textFirstName, textLastName, textGender, textEmail, textAddress,
textPhoneNumber, textUsername;

//Variabel Kolom editText


EditText editTextFirstName, editTextLastName, editTextEmail, editTextAddress,
editTextPhoneNumber, editTextUsername;

//Radio Button Male/Female


RadioGroup radioGroup;
RadioButton radioButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

button = findViewById(R.id.buttonSignUp);
editTextFirstName = findViewById(R.id.textFirstName);
editTextLastName = findViewById(R.id.textLastName);
editTextEmail = findViewById(R.id.textEmail);
editTextAddress = findViewById(R.id.textAddress);
editTextPhoneNumber = findViewById(R.id.textPhoneNumber);
editTextUsername = findViewById(R.id.textUserName);
radioGroup = findViewById(R.id.radioGender);

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
textFirstName = editTextFirstName.getText().toString();
textLastName = editTextLastName.getText().toString();
textEmail = editTextEmail.getText().toString();
textAddress = editTextAddress.getText().toString();
textPhoneNumber = editTextPhoneNumber.getText().toString();
textUsername = editTextUsername.getText().toString();
//Radio Button Male/Female
int selectedID = radioGroup.getCheckedRadioButtonId();
radioButton = findViewById(selectedID);
textGender = radioButton.getHint().toString();

//Kirim teks ke Activity Lain


Intent intent = new Intent(MainActivity.this,
Activity2.class);
intent.putExtra("firstName", textFirstName);
intent.putExtra("lastName",textLastName);
intent.putExtra("email", textEmail);
intent.putExtra("address", textAddress);
intent.putExtra("phoneNumber", textPhoneNumber);
intent.putExtra("username", textUsername);
intent.putExtra("gender", textGender);

startActivity(intent);
}
});
}
}

You might also like