Ad Code

Responsive Advertisement

Basic Android Program 08

Question 08: Write a program to accept and display personal information of the student.

Download hole Program / Project code, by clicking following link:

What is the name of the folder that contains the R.java file?
a. src
b. res
c. bin
d. gen.

The answer is d. gen. In Android Studio, the R.java file is generated automatically by the Android build system and contains references to all the resources used in an Android app, such as layout files, images, and strings. This file is generated in the "gen" folder, which is short for "generated", and is located in the app module directory of an Android project. The "gen" folder is automatically created by the Android build system when the project is built, and should not be modified directly. Any changes to resources or layouts should be made in the "res" folder, which contains all the non-code resources used in the app, such as layouts, strings, images, and other assets. It's worth noting that in newer versions of Android Studio and the Android build system, the "gen" folder has been replaced by the "build" folder, which contains all the generated files and artifacts created during the build process, including the R.java file. However, the R.java file itself is still located in a subdirectory of the "build" folder named "generated".


Programming Code:

Following code write in: MainActivity.java
package com.go2collage.practical_08;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

// Declare variables
private EditText name, dob, address, email, contact;
private Button submit;

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

// initialize variables
submit = findViewById(R.id.submitbtn);

name = findViewById(R.id.edName);
dob = findViewById(R.id.edDob);
address = findViewById(R.id.edAddress);
email = findViewById(R.id.edEmail);
contact = findViewById(R.id.edContact);

submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

// converting text to String
String n = name.getText().toString();
String d = dob.getText().toString();
String add = address.getText().toString();
String e = email.getText().toString();
String number = contact.getText().toString();

// if any fields is empty then
if (n.isEmpty() || d.isEmpty() || add.isEmpty() || e.isEmpty() || number.isEmpty())
{
Toast.makeText(MainActivity.this, "Please fill all the fields", Toast.LENGTH_SHORT).show();
}

// else all the fields filled then
else {
Toast.makeText(MainActivity.this, n +"\n"+ d +"\n"+ add +"\n"+ e +"\n"+ number, Toast.LENGTH_SHORT).show();
}

}
});


}
}

Following code write in: activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
android:layout_margin="20dp">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="go2collage"
android:layout_marginTop="20dp"
android:textAlignment="center"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginBottom="50dp"
tools:ignore="HardcodedText" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Personal Information of Student"
android:textColor="@color/black"
android:textStyle="bold"
android:textSize="20sp"
android:layout_marginBottom="20dp"
android:textAlignment="center"
tools:ignore="HardcodedText" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/edName"
android:layout_marginTop="10dp"
android:ems="10"
android:hint="Enter your name"
android:inputType="textPersonName"
android:minHeight="48dp"
android:textColorHint="#757575"
android:textSize="18sp"
tools:ignore="Autofill,HardcodedText" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/edDob"
android:layout_marginTop="10dp"
android:ems="10"
android:hint="Enter Date of Birth"
android:inputType="date"
android:minHeight="48dp"
android:textColorHint="#757575"
android:textSize="18sp"
tools:ignore="Autofill,HardcodedText" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/edAddress"
android:layout_marginTop="10dp"
android:ems="10"
android:hint="Enter your Address"
android:inputType="textCapCharacters"
android:minHeight="48dp"
android:textColorHint="#757575"
android:textSize="18sp"
tools:ignore="Autofill,HardcodedText" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/edEmail"
android:layout_marginTop="10dp"
android:ems="10"
android:hint="Enter Email ID"
android:inputType="textEmailAddress"
android:minHeight="48dp"
android:textColorHint="#757575"
android:textSize="18sp"
tools:ignore="Autofill,HardcodedText" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/edContact"
android:layout_marginTop="10dp"
android:ems="10"
android:hint="Enter Mobile Number"
android:inputType="date"
android:minHeight="48dp"
android:textColorHint="#757575"
android:textSize="18sp"
tools:ignore="Autofill,HardcodedText" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/submitbtn"
android:text="Submit"
android:textSize="18sp"
android:layout_marginTop="50dp"
tools:ignore="HardcodedText" />

</LinearLayout>

Output:



Post a Comment

0 Comments

Ad Code

Responsive Advertisement