Program 2-1 - Merged
Program 2-1 - Merged
XML:
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:padding="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Registration Form!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:textSize="24sp"
android:layout_gravity="center"
android:layout_marginTop="30dp"/>
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="48dp"
android:ems="10"
android:inputType="text"
android:padding="10dp"/>
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="48dp"
android:ems="10"
android:inputType="textPassword"
android:hint="Enter Password"
android:padding="10dp"/>
<EditText
android:id="@+id/address"
android:layout_width="match_parent"
android:layout_height="100dp"
android:ems="10"
android:inputType="textMultiLine"
android:maxLines="5"/>
<RadioGroup
android:id="@+id/gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/male"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Male" />
<RadioButton
android:id="@+id/female"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Female" />
</RadioGroup>
<EditText
android:id="@+id/age"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:ems="10"
android:inputType="number"
android:hint="Enter Age"/>
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Submit" />
<TextView
android:id="@+id/toDisplayData"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"/>
</[Link]>
[Link]
package [Link].labact2;
import [Link];
import [Link].*;
import [Link];
RadioGroup gender;
TextView toDisplayData;
@Override
[Link](savedInstanceState);
setContentView([Link].activity_main);
username = findViewById([Link]);
password = findViewById([Link]);
address = findViewById([Link]);
age = findViewById([Link]);
gender = findViewById([Link]);
toDisplayData = findViewById([Link]);
findViewById([Link]).setOnClickListener(v -> {
return;
String g = ((RadioButton)
findViewById([Link]())).getText().toString();
"\nGender: " + g +
});
return false;
}
A very compact version of the same java code written above. But this very complex to
understand. (Not recommended for exams, Use it wisely)
package [Link].labact2;
import [Link];
import [Link].*;
import [Link];
[Link](s); setContentView([Link].activity_main);
EditText
u=findViewById([Link]),p=findViewById([Link]),a=findViewById([Link]
ess),g=findViewById([Link]);
findViewById([Link]).setOnClickListener(v->{
if([Link]().toString().isEmpty()||[Link]().toString().isEmpty()||[Link]().toString()
.isEmpty()||[Link]().toString().isEmpty()||[Link]()==-1)
});
}
Program 3:
Develop standard calculator application to perform
basic calculations like addition, subtraction,
multiplication and division using 2 EditText and 1
TextView for displaying result.
XML:
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="15dp"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autofillHints="Calc"
android:text="@string/the_great_calculator_app"
android:textSize="34sp"
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.023" />
<EditText
android:id="@+id/num1"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginBottom="484dp"
android:ems="10"
android:hint="@string/enter_1st_number"
android:inputType="numberDecimal"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/result" />
<EditText
android:id="@+id/num2"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginBottom="444dp"
android:ems="10"
android:hint="@string/enter_2nd_number"
android:inputType="numberDecimal"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="@+id/result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/result"
android:textAlignment="center"
android:textSize="34sp"
app:layout_constraintBottom_toTopOf="@+id/num2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2"
app:layout_constraintVertical_bias="0.315" />
<Button
android:id="@+id/btnSub"
android:layout_width="92dp"
android:layout_height="90dp"
android:layout_marginTop="31dp"
android:layout_marginBottom="300dp"
android:text="@string/sub"
android:textSize="40sp"
app:cornerRadius="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/btnMul"
app:layout_constraintStart_toEndOf="@+id/btnAdd"
app:layout_constraintTop_toBottomOf="@+id/num1"
app:layout_constraintVertical_bias="1.0" />
<Button
android:id="@+id/btnDiv"
android:layout_width="92dp"
android:layout_height="90dp"
android:layout_marginTop="31dp"
android:layout_marginBottom="300dp"
android:text="@string/div"
android:textSize="40sp"
app:cornerRadius="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/btnMul"
app:layout_constraintTop_toBottomOf="@+id/num1"
app:layout_constraintVertical_bias="1.0" />
<Button
android:id="@+id/btnAdd"
android:layout_width="92dp"
android:layout_height="90dp"
android:layout_marginTop="30dp"
android:layout_marginBottom="300dp"
android:text="@string/add"
android:textSize="40sp"
app:cornerRadius="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/btnSub"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/num1"
app:layout_constraintVertical_bias="1.0" />
<Button
android:id="@+id/btnMul"
android:layout_width="92dp"
android:layout_height="90dp"
android:layout_marginTop="31dp"
android:layout_marginBottom="300dp"
android:text="@string/x"
android:textSize="40sp"
app:cornerRadius="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/btnDiv"
app:layout_constraintStart_toEndOf="@+id/btnSub"
app:layout_constraintTop_toBottomOf="@+id/num1"
app:layout_constraintVertical_bias="1.0" />
<TextView
android:id="@+id/textView"
android:layout_width="105dp"
android:layout_height="96dp"
android:layout_marginStart="162dp"
android:layout_marginTop="88dp"
android:layout_marginEnd="176dp"
android:layout_marginBottom="208dp"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btnSub" />
</[Link]>
[Link]
package [Link].lab3;
import [Link];
import [Link];
import [Link].*;
import [Link];
TextView result;
@Override
[Link](savedInstanceState);
setContentView([Link].activity_main);
num1 = findViewById([Link].num1);
num2 = findViewById([Link].num2);
result = findViewById([Link]);
[Link]();
getWindow().setSoftInputMode([Link].SOFT_INPUT_STATE_A
LWAYS_VISIBLE);
findViewById([Link]).setOnClickListener(v -> calculate('+'));
String s1 = [Link]().toString().trim();
String s2 = [Link]().toString().trim();
if ([Link]() || [Link]()) {
return;
double a = [Link](s1);
double b = [Link](s2);
double res = 0;
switch (op) {
case '/':
if (b == 0) {
res = a / b;
break;
[Link]([Link](res));
}
A compact version of the same java code written above, But its complex to
understand. (Not recommended for exams)
package [Link].lab3;
import [Link];
import [Link];
import [Link].*;
import [Link];
[Link](b); setContentView([Link].activity_main);
n1 = findViewById([Link].num1); n2 = findViewById([Link].num2); r =
findViewById([Link]);
[Link]();
getWindow().setSoftInputMode([Link].SOFT_INPUT_STATE_ALW
AYS_VISIBLE);
double x=[Link](a),y=[Link](b),z=0;
[Link](""+z);
}
Program 4:
Design an android application for creating login form
using table layout.
XML:
<TableLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="1"
android:paddingTop="100dp"
>
<TableRow>
<TextView
android:text="Username:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"/>
<EditText
android:id="@+id/editTextUsername"
android:layout_width="match_parent"
android:layout_height="48dp"
android:hint="Enter Username"
android:inputType="textPersonName"/>
</TableRow>
<TableRow>
<TextView
android:text="Password:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"/>
<EditText
android:id="@+id/editTextPassword"
android:layout_width="match_parent"
android:layout_height="48dp"
android:hint="Enter Password"
android:inputType="textPassword"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/buttonLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"/>
</TableRow>
</TableLayout>
[Link]
package [Link].prog4;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
Button loginButton;
@Override
[Link](savedInstanceState);
setContentView([Link].activity_main);
usernameEditText = findViewById([Link]);
passwordEditText = findViewById([Link]);
loginButton = findViewById([Link]);
[Link](view -> {
String username = [Link]().toString();
} else {
});
}
Program 5:
Develop an android application to register a form in
first activity and display the registered information in
second activity using intents.
Activity_main.XML:
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/registeration_form"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="28dp"
android:layout_marginBottom="68dp"
android:text="Registration Form"
android:textSize="20dp"
android:textStyle="bold"
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.19" />
<EditText
android:id="@+id/etName"
android:layout_width="0dp"
android:layout_height="48dp"
android:hint="Enter Name"
android:padding="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/registeration_form"
app:layout_constraintVertical_bias="0.050000012"
android:inputType="text"
/>
<EditText
android:id="@+id/etEmail"
android:layout_width="0dp"
android:layout_height="48dp"
android:hint="Enter Email"
android:inputType="textEmailAddress"
app:layout_constraintTop_toBottomOf="@id/etName"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:padding="10dp"/>
<EditText
android:id="@+id/etPhone"
android:layout_width="0dp"
android:layout_height="48dp"
android:hint="Enter Phone"
android:inputType="phone"
app:layout_constraintTop_toBottomOf="@id/etEmail"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:padding="10dp" />
<EditText
android:id="@+id/etAge"
android:layout_width="0dp"
android:layout_height="48dp"
android:hint="Age"
android:inputType="number"
app:layout_constraintTop_toBottomOf="@id/etPhone"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:padding="10dp"/>
<EditText
android:id="@+id/etGender"
android:layout_width="0dp"
android:layout_height="48dp"
android:hint="Enter Gender"
app:layout_constraintTop_toBottomOf="@id/etAge"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:padding="10dp" />
<Button
android:id="@+id/btnSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/etGender"
app:layout_constraintVertical_bias="0.120000005"
android:text="Button" />
</[Link]>
Activity_main2.xml:
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity2">
<TextView
android:id="@+id/tvDisplay"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="24sp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:padding="20dp" />
</[Link]>
[Link]:
package [Link].pro5;
import [Link];
import [Link];
import [Link].*;
import [Link];
@Override
[Link](savedInstanceState);
setContentView([Link].activity_main);
name = findViewById([Link]);
email = findViewById([Link]);
phone = findViewById([Link]);
age = findViewById([Link]);
gender = findViewById([Link]);
if (submit != null) {
[Link](v -> {
[Link]("NAME", [Link]().toString());
[Link]("EMAIL", [Link]().toString());
[Link]("PHONE", [Link]().toString());
[Link]("AGE", [Link]().toString());
[Link]("GENDER", [Link]().toString());
startActivity(i);
});
}
[Link]:
package [Link].pro5;
import [Link];
import [Link];
import [Link];
@Override
[Link](b);
setContentView([Link].activity_main2);
TextView tv = findViewById([Link]);
Bundle i = getIntent().getExtras();
if (i != null) {
[Link](info);
}
}
Program 6 :
Design an android application to send SMS using
Intent
XML:
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toTopOf="@+id/phoneNumber"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.65999997" />
<EditText
android:id="@+id/phoneNumber"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginTop="56dp"
android:inputType="phone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<EditText
android:id="@+id/messageText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="35dp"
android:layout_marginBottom="486dp"
android:gravity="top"
android:hint="Enter Message"
android:inputType="textMultiLine"
android:lines="3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/phoneNumber" />
<Button
android:id="@+id/sendSmsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="50dp"
android:layout_marginEnd="282dp"
android:layout_marginBottom="388dp"
android:text="Send SMS"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/messageText" />
</[Link]>
[Link]:
package [Link].lab61;
import [Link];
import [Link];
import [Link];
import [Link].*;
import [Link];
[Link](b);
setContentView([Link].activity_main);
findViewById([Link]).setOnClickListener(v -> {
if ([Link]() || [Link]()) {
return;
try {
startActivity(new Intent(Intent.ACTION_VIEW, [Link]("smsto:" +
num)).putExtra("sms_body", msg));
} catch (Exception e) {
});
}
Program 7:
Create an android application using fragments.
Activity_main.XML :
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<Button
android:id="@+id/btnFragment1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
android:text="Frag ONE"
app:cornerRadius="5dp" />
<Button
android:id="@+id/btnFragment2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
android:text="Frag TWO"
app:cornerRadius="5dp" />
<Button
android:id="@+id/btnFragment3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
android:text="Frag THREE"
app:cornerRadius="5dp" />
</LinearLayout>
<FrameLayout
android:id="@+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Fragment_one.xml :
<FrameLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#EF0808"
tools:context=".FragmentOne">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textColor="#F2EDED"
android:textSize="34sp"
android:textStyle="bold" />
</FrameLayout>
Fragment_two.xml :
<FrameLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#2BEF08"
tools:context=".FragmentTwo">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textColor="#0D0C0C"
android:textSize="34sp"
android:textStyle="bold" />
</FrameLayout>
Fragment_three.xml :
<FrameLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#0832EF"
tools:context=".FragmentThree">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textColor="#0D0C0C"
android:textSize="34sp"
android:textStyle="bold" />
</FrameLayout>
[Link] :
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);
loadFragment(new FragmentOne());
}
[Link] :
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
Bundle savedInstanceState) {
[Link](0xFFEF0808); //Red
return view;
}
[Link] :
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
Bundle savedInstanceState) {
[Link](0xFF4CAF50); //Green
return view;
}
[Link] :
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
Bundle savedInstanceState) {
[Link](0xFF2196F3); //Blue
return view;
}
Program 8 :
Design an application that draws basic graphical
shapes (rectangle, circle)
No XML for this project :
[Link] :
package [Link].lab8drawing;
import [Link];
import [Link].*;
import [Link];
import [Link].*;
import [Link];
public ShapeView(Context c) {
super(c);
[Link](0xFF2196F3); [Link]([Link]);
switch(i){
}
Program 9:
Develop a mobile application that create, save, update
and delete data in a database.
Activity_main.xml :
<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="8dp">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:id="@+id/taskList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Tasks"
android:padding="4dp" />
</ScrollView>
<EditText
android:id="@+id/idInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="ID"
android:inputType="number" />
<EditText
android:id="@+id/taskInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Task" />
<EditText
android:id="@+id/notesInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Notes" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton
android:id="@+id/addBtn"
android:layout_width="48dp"
android:layout_height="48dp"
android:src="@android:drawable/ic_input_add" />
<ImageButton
android:id="@+id/viewBtn"
android:layout_width="48dp"
android:layout_height="48dp"
android:src="@android:drawable/ic_menu_view" />
<ImageButton
android:id="@+id/updateBtn"
android:layout_width="48dp"
android:layout_height="48dp"
android:src="@android:drawable/ic_menu_edit" />
<ImageButton
android:id="@+id/deleteBtn"
android:layout_width="48dp"
android:layout_height="48dp"
android:src="@android:drawable/ic_menu_delete" />
</LinearLayout>
</LinearLayout>
[Link] :
package [Link];
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
[Link](b); setContentView([Link].activity_main);
i=findViewById([Link]); t=findViewById([Link]);
n=findViewById([Link]); o=findViewById([Link]);
int[] btns={[Link],[Link],[Link],[Link]};
for(int j=0;j<[Link];j++) {
findViewById(btns[k]).setOnClickListener(v->{
});
void v() {
}
Program 10 :
Create a user registration application that stores the
user details in a database table.
Xml :
<EditText
android:id="@+id/editName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name" />
<EditText
android:id="@+id/editEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email" />
<EditText
android:id="@+id/editPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword" />
<Button
android:id="@+id/btnRegister"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Register" />
</LinearLayout>
[Link] :
package [Link];
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
public class MainActivity extends AppCompatActivity {
EditText n,e,p;SQLiteDatabase d;
protected void onCreate(Bundle
b){[Link](b);setContentView([Link].activity_main);
n=findViewById([Link]); e=findViewById([Link]);
p=findViewById([Link]);
d=new DbHelper(this).getWritableDatabase();
findViewById([Link]).setOnClickListener(v->r());
}
void r(){
String N=[Link]().toString(),E=[Link]().toString(),P=[Link]().toString();
if([Link]()||[Link]()||[Link]()){[Link](this,"Fill all
fields",Toast.LENGTH_SHORT).show();return;}
ContentValues v=new
ContentValues();[Link]("name",N);[Link]("email",E);[Link]("password",P);
if([Link]("users",null,v)!=-
1){[Link](this,"Success",Toast.LENGTH_SHORT).show();[Link]("");[Link]("");
[Link]("");}
else [Link](this,"Failed",Toast.LENGTH_SHORT).show();
}
class DbHelper extends SQLiteOpenHelper{
DbHelper(Context c){super(c,"userdb",null,1);
}
public void onCreate(SQLiteDatabase d){
[Link]("CREATE TABLE users (id INTEGER PRIMARY KEY,name TEXT,email
TEXT,password TEXT)");
}
public void onUpgrade(SQLiteDatabase d,int o,int n){
[Link]("DROP TABLE IF EXISTS users");onCreate(d);
}
}
}