0% found this document useful (0 votes)
3 views

Simple Android App

This document outlines the creation of a simple Android app with three activities to capture user details: MainActivity for the user's name, DetailsActivity for email and phone number, and SummaryActivity to display the captured information. It provides instructions for setting up the project, creating necessary XML resource files, designing layouts, and linking activities through Java code. The app utilizes various resources such as strings, colors, dimensions, and styles to enhance its functionality and appearance.

Uploaded by

amina22azam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Simple Android App

This document outlines the creation of a simple Android app with three activities to capture user details: MainActivity for the user's name, DetailsActivity for email and phone number, and SummaryActivity to display the captured information. It provides instructions for setting up the project, creating necessary XML resource files, designing layouts, and linking activities through Java code. The app utilizes various resources such as strings, colors, dimensions, and styles to enhance its functionality and appearance.

Uploaded by

amina22azam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

SIMPLE ANDROID APP

Creating an Android app with three activities that capture and link user details
1. Setting Up Your Project
• Open Android Studio and create a new project.
• Select an "Empty Views Activity" template and name your project.
2. Resources
Let's create the required XML files for strings, colors, dimens, and styles. These files will help
you manage resources efficiently.

strings.xml
Define all the string resources your app will use:
<resources>
<string name="app_name">UserDetailsApp</string>
<string name="name_prompt">Enter Your Name:</string>
<string name="email_prompt">Enter Your Email:</string>
<string name="phone_prompt">Enter Your Phone Number:</string>
<string name="summary_title">Summary of Details</string>
<string name="name_label">Name:</string>
<string name="email_label">Email:</string>
<string name="phone_label">Phone:</string>
<string name="next_button">Next</string>
</resources>

colors.xml
Define all the colors used in your app:
<resources>
<color name="colorPrimary">#6200EE</color>
<color name="colorPrimaryDark">#3700B3</color>
<color name="colorAccent">#03DAC5</color>
<color name="colorText">#FFFFFF</color>
</resources>
dimens.xml
Define all the dimensions used in your app:
<resources>
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="text_size">18sp</dimen>
<dimen name="margin_top">20dp</dimen>
<dimen name="margin_large">50dp</dimen>
</resources>
styles.xml
Define the styles and themes for your app:
<resources>
<!-- Base application theme -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:textColor">@color/colorText</item>
</style>

<!-- Button style -->


<style name="ButtonStyle">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_gravity">center</item>
<item name="android:marginTop">@dimen/margin_top</item>
</style>

<!-- TextView style -->


<style name="TextViewStyle">
<item name="android:textSize">@dimen/text_size</item>
<item name="android:layout_marginBottom">@dimen/margin_top</item>
</style>
</resources>
3. Designing the Layouts: For simplicity, we’ll create three activities:
• MainActivity for capturing the user's name.
• DetailsActivity for capturing the user's email and phone number.
• SummaryActivity for displaying the captured details.
MainActivity Layout (activity_main.xml)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Your Name:"
android:layout_marginTop="50dp"
android:layout_centerHorizontal="true" />

<EditText
android:id="@+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tvName"
android:layout_margin="20dp"
android:hint="Name" />

<Button
android:id="@+id/btnNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:layout_below="@id/etName"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp" />
</RelativeLayout>
DetailsActivity Layout (activity_details.xml)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Your Email:" />

<EditText
android:id="@+id/etEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Your Phone Number:" />

<EditText
android:id="@+id/etPhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Phone Number" />

<Button
android:id="@+id/btnNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:layout_gravity="center"
android:layout_marginTop="20dp" />
</LinearLayout>
SummaryActivity Layout (activity_summary.xml)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp">

<TextView
android:id="@+id/tvSummary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Summary of Details"
android:textSize="18sp"
android:layout_marginBottom="30dp"/>

<TextView
android:id="@+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tvSummary"
android:layout_marginBottom="20dp" />

<TextView
android:id="@+id/tvEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tvName"
android:layout_marginBottom="20dp" />

<TextView
android:id="@+id/tvPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tvEmail" />
</RelativeLayout>
3. Linking Activities
MainActivity.java

public class MainActivity extends AppCompatActivity {

private EditText etName;


private Button btnNext;

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

etName = findViewById(R.id.etName);
btnNext = findViewById(R.id.btnNext);

btnNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name = etName.getText().toString();
Intent intent = new Intent(MainActivity.this, DetailsActivity.class);
intent.putExtra("name", name);
startActivity(intent);
}
});
}
}
DetailsActivity.java
public class DetailsActivity extends AppCompatActivity {
private EditText etEmail, etPhone;
private Button btnNext;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);

etEmail = findViewById(R.id.etEmail);
etPhone = findViewById(R.id.etPhone);
btnNext = findViewById(R.id.btnNext);

btnNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String email = etEmail.getText().toString();
String phone = etPhone.getText().toString();
Intent intent = new Intent(DetailsActivity.this, SummaryActivity.class);
intent.putExtra("name", getIntent().getStringExtra("name"));
intent.putExtra("email", email);
intent.putExtra("phone", phone);
startActivity(intent);
}
});
}
}
SummaryActivity.java
java
public class SummaryActivity extends AppCompatActivity {

private TextView tvName, tvEmail, tvPhone;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_summary);

tvName = findViewById(R.id.tvName);
tvEmail = findViewById(R.id.tvEmail);
tvPhone = findViewById(R.id.tvPhone);

Intent intent = getIntent();


String name = intent.getStringExtra("name");
String email = intent.getStringExtra("email");
String phone = intent.getStringExtra("phone");

tvName.setText("Name: " + name);


tvEmail.setText("Email: " + email);
tvPhone.setText("Phone: " + phone);
}
}

You might also like