0% found this document useful (0 votes)
50 views95 pages

AP All Practical

Uploaded by

chessaum
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)
50 views95 pages

AP All Practical

Uploaded by

chessaum
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

Practical : 1

Aim: To print “hello world” using [Link] file in android application.

CODE:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#70C9F1"
tools:context=".MainActivity">

<TextView
android:layout_width="150dp"
android:layout_height="60dp"
android:background="#02415E"
android:paddingTop="17dp"
android:text="Hello World!"
android:textAlignment="center"
android:textColor="#03A9F4"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</[Link]>
[Link]
package [Link].practical1;

import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
}

OUTPUT:
Practical : 2
Aim: Create an Android App to implement Activity life cycle.

CODE:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</[Link]>

[Link]
package [Link].practical2;

import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


Toast toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
[Link](getApplicationContext(), "onCreate Called",
Toast.LENGTH_LONG).show();
}
protected void onStart() {
[Link]();
[Link](getApplicationContext(), "onStart Called",
Toast.LENGTH_LONG).show();
}
@Override
protected void onRestart() {
[Link]();
[Link](getApplicationContext(), "onRestart Called",
Toast.LENGTH_LONG).show();
}
protected void onPause() {
[Link]();
[Link](getApplicationContext(), "onPause Called",
Toast.LENGTH_LONG).show();
}
protected void onResume() {
[Link]();
[Link](getApplicationContext(), "onResume Called",
Toast.LENGTH_LONG).show();
}
protected void onStop() {
[Link]();
[Link](getApplicationContext(), "onStop Called",
Toast.LENGTH_LONG).show();
}
protected void onDestroy() {
[Link]();
[Link](getApplicationContext(), "onDestroy Called",
Toast.LENGTH_LONG).show();
}
}

OUTPUT:
Practical : 3
Aim: To perform button click event in android application. There are 3
different methods used to handle button click event. (Mention All 3
methods)

CODE:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:gravity="center|center_horizontal"
android:orientation="vertical"
tools:context=".MainActivity">

<Button
android:id="@+id/btnToast1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1st way"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="147dp"
tools:layout_editor_absoluteY="75dp" />

<Button
android:id="@+id/btnToast2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="2nd way"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="147dp"
tools:layout_editor_absoluteY="147dp" />

<Button
android:id="@+id/btnToast3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:onClick="thway"
android:text="3rd way"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="147dp"
tools:layout_editor_absoluteY="220dp" />

</LinearLayout>

[Link]
package [Link].practical3;

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

// ( OnClickListener event 3 ways)


public class MainActivity extends AppCompatActivity implements [Link] {

Button b1,b2,b3;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

b1=findViewById([Link].btnToast1);
b2=findViewById([Link].btnToast2);
b3=findViewById([Link].btnToast3);

[Link](new [Link]() {
@Override
public void onClick(View view) {
[Link]([Link], "1st way ", Toast.LENGTH_SHORT).show();
}
});

[Link](this);
}

@Override
public void onClick(View view) {
[Link](this, "2nd way", Toast.LENGTH_SHORT).show();

public void thway(View view) {


[Link](this, "3rd way", Toast.LENGTH_SHORT).show();
}
}
Practical : 4
Aim: Create an Android App to design simple calculator.

CODE:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_blue_light"
android:orientation="vertical"
android:padding="20dp"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="CALCULATOR"
android:textColor="@android:color/black"
android:textSize="25sp" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:orientation="horizontal">
<EditText
android:id="@+id/first_no"
android:layout_width="102dp"
android:layout_height="59dp"
android:layout_marginHorizontal="50dp"
android:ems="10"
android:hint="Enter"
android:textColorHint="@color/black"/>
<EditText
android:id="@+id/second_no"
android:layout_width="102dp"
android:layout_height="59dp"
android:ems="10"
android:hint="Enter"
android:textColorHint="@color/black"/>

</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:orientation="horizontal">
<TextView
android:id="@+id/answer"
android:layout_width="102dp"
android:layout_height="59dp"
android:layout_marginHorizontal="50dp"
android:hint="ans"
android:textSize="35sp"
android:textColorHint="@color/black"/>
</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="250dp"
android:layout_marginBottom="30dp"
android:orientation="vertical">
<Button
android:id="@+id/sub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="-"
android:textSize="25sp" />
<Button
android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="+"
android:textSize="25sp"
tools:ignore="OnClick" />
<Button
android:id="@+id/div"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="/"
android:textSize="25sp" />
<Button
android:id="@+id/mul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="X"
android:textSize="25sp" />
<Button
android:id="@+id/equals"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="="
android:textSize="35sp" />
</LinearLayout>

</LinearLayout>

[Link]
package [Link].practical4;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
EditText no1 , no2;
Button add ,mul ,div , sub,equal;
TextView answer;
double ans = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
// for text views
no1 = findViewById([Link].first_no);
no2 = findViewById([Link].second_no);

// for button with operations


add = findViewById([Link]);
mul = findViewById([Link]);
div = findViewById([Link]);
sub = findViewById([Link]);

// for equal to button


equal = findViewById([Link]);

// for answer field


answer = findViewById([Link]);

[Link](new [Link]() {
@Override
public void onClick(View v) {
String num1 = [Link]().toString();
String num2 = [Link]().toString();
if ([Link]() || [Link]()) {
[Link](getApplicationContext(),"Enter
Numbers",Toast.LENGTH_SHORT).show();
}
else {
double a = [Link]([Link]().toString());
double b = [Link]([Link]().toString());
ans = a + b;
}
}
});
[Link](new [Link]() {
@Override
public void onClick(View v) {
String num1 = [Link]().toString();
String num2 = [Link]().toString();
if ([Link]() || [Link]()) {
[Link](getApplicationContext(),"Enter
Numbers",Toast.LENGTH_SHORT).show();
}
else {
double a = [Link]([Link]().toString());
double b = [Link]([Link]().toString());
ans = a - b;
}
}
});
[Link](new [Link]() {
@Override
public void onClick(View v) {
String num1 = [Link]().toString();
String num2 = [Link]().toString();
if ([Link]() || [Link]()) {
[Link](getApplicationContext(),"Enter
Numbers",Toast.LENGTH_SHORT).show();
}
else {
double a = [Link]([Link]().toString());
double b = [Link]([Link]().toString());
ans = a * b;
}
}
});
[Link](new [Link]() {
@Override
public void onClick(View v) {
String num1 = [Link]().toString();
String num2 = [Link]().toString();

if ([Link]() || [Link]()) {
[Link](getApplicationContext(), "Enter Numbers",
Toast.LENGTH_SHORT).show();
} else {
double a = [Link]([Link]().toString());
double b = [Link]([Link]().toString());
if (b != 0)
ans = a / b;
else
[Link](getApplicationContext(), "Enter Valid Numbers",
Toast.LENGTH_SHORT).show();
}
}
});
[Link](new [Link]() {
@Override
public void onClick(View v) {
String ans1 = [Link](ans);
[Link](ans1);
ans= 0;
}
});

}
}

OUTPUT:
Practical : 5
Aim: To implement Splash screen(Welcome Screen) without animation in
android.

CODE:
activity_main.xml
?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:id="@+id/idRLContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"

android:orientation="vertical"
tools:context=".MainActivity">
<!-- android:background="@color/material_dynamic_primary80"-->

<!--on below line we are adding an image view-->


<ImageView
android:id="@+id/idIVLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginStart="25dp"
android:layout_marginTop="25dp"
android:layout_marginEnd="25dp"
android:layout_marginBottom="25dp"
android:src="@drawable/splash_icon" />

<!--on below line we are creating progress bar-->


<ProgressBar
android:id="@+id/idPBLoading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/idIVLogo"
android:layout_centerInParent="true"
android:indeterminateTint="@color/white" />
</RelativeLayout>

activity_main2.xml

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout
xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity2">

<!--on below line we are creating


a text for our app-->
<TextView
android:id="@+id/idTVHeading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="20dp"
android:gravity="center"
android:padding="10dp"
android:text="Welcome"
android:textAlignment="center"
android:textColor="@color/black"
android:textSize="20sp"
android:textStyle="bold" />

</RelativeLayout>

[Link]

package [Link].practical5;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);

// on below line we are configuring our window to full screen


getWindow().setFlags([Link].FLAG_FULLSCREEN,
[Link].FLAG_FULLSCREEN);

setContentView([Link].activity_main);

// on below line we are calling handler to run a task


// for specific time interval
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// on below line we are
// creating a new intent
Intent i = new Intent([Link], [Link]);

// on below line we are


// starting a new activity.
startActivity(i);

// on the below line we are finishing


// our current activity.
finish();
}
}, 2000);

}
}

[Link]

package [Link].practical5;

import [Link];
import [Link];
public class MainActivity2 extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main2);
}
}

Output :
Practical : 6
Aim: Create an Android App to perform Toast.
CODE:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:gravity="center|center_horizontal"
android:orientation="vertical"
tools:context=".MainActivity">

<Button
android:id="@+id/btnToast1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1st way"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="147dp"
tools:layout_editor_absoluteY="75dp" />

<Button
android:id="@+id/btnToast2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="2nd way"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="147dp"
tools:layout_editor_absoluteY="147dp" />

<Button
android:id="@+id/btnToast3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:onClick="thway"
android:text="3rd way"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="147dp"
tools:layout_editor_absoluteY="220dp" />

</LinearLayout>

[Link]
package [Link].practical3;

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
// ( OnClickListener event 3 ways)
public class MainActivity extends AppCompatActivity implements [Link] {

Button b1,b2,b3;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

b1=findViewById([Link].btnToast1);
b2=findViewById([Link].btnToast2);
b3=findViewById([Link].btnToast3);

[Link](new [Link]() {
@Override
public void onClick(View view) {
[Link]([Link], "1st way ", Toast.LENGTH_SHORT).show();
}
});

[Link](this);
}

@Override
public void onClick(View view) {
[Link](this, "2nd way", Toast.LENGTH_SHORT).show();
}

public void thway(View view) {


[Link](this, "3rd way", Toast.LENGTH_SHORT).show();
}
}

OUTPUT:
Practical : 7
Aim: Create an Android App to display Dialog Box in android.
CODE:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="180dp"
android:gravity="center_horizontal"
android:text="Press The Back Button of Your Phone."
android:textSize="30dp"
android:textStyle="bold" />
</RelativeLayout>

[Link]
package [Link].practical7;

import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}

// Declare the onBackPressed method when the back button is pressed this method will call
@Override
public void onBackPressed() {
// Create the object of AlertDialog Builder class
[Link]();
[Link] builder = new [Link]([Link]);

// Set the message show for the Alert time


[Link]("Do you want to exit ?");

// Set Alert Title


[Link]("Alert !");

// Set Cancelable false for when the user clicks on the outside the Dialog Box then it will
remain show
[Link](false);

// Set the positive button with yes name Lambda OnClickListener method is use of
DialogInterface interface.
[Link]("Yes", ([Link]) (dialog, which) -> {
// When the user click yes button then app will close
finish();
});
// Set the Negative button with No name Lambda OnClickListener method is use of
DialogInterface interface.
[Link]("No", ([Link]) (dialog, which) -> {
// If user click no then dialog box is canceled.
[Link]();
});

// Create the Alert dialog


AlertDialog alertDialog = [Link]();
// Show the Alert Dialog box
[Link]();
}
}

Output :
Practical : 8
Aim: To perform Explicit Intent in android.

CODE:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F47DC5"
tools:context=".MainActivity">

<TextView
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Welcome to Home Screen"
android:textAlignment="center"
android:textSize="28sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#D6336B"
android:onClick="newsScreen"
android:text="Go to New Screen"
android:textColor="#000000"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText" />
</[Link]>

[Link]
package [Link].practical9;
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
public void newsScreen(View view) {
Intent i = new Intent(getApplicationContext(), [Link]);
startActivity(i);
}
}

activity_main2.xml
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F47DC5"
tools:context=".MainActivity2">

<TextView
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Welcome to New Screen"
android:textAlignment="center"
android:textSize="28sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#D6336B"
android:onClick="homeScreen"
android:text="Go to Home Screen"
android:textColor="@color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText" />
</[Link]>

[Link]
package [Link].practical9;

import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity2 extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main2);
}
public void homeScreen(View view) {
Intent i = new Intent(getApplicationContext(), [Link]);
startActivity(i);
}
}
Output :
Practical : 9
Aim: Create an Android App to perform Implicit Intent - Messages wiring
components together. The source and destination for the content transfer
are not known. Only the task and the action to be performed are known.

CODE:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E5A3F1"
tools:context=".MainActivity">

<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Search here"
android:textColorHint="@color/black"
android:minHeight="48dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="search"
android:text="Search"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText" />

</[Link]>

[Link]
package [Link].practical8;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
EditText editText;
Button button;
[Link](savedInstanceState);
setContentView([Link].activity_main);
button = findViewById([Link]);
editText = (EditText) findViewById([Link]);

[Link](new [Link]() {
@Override
public void onClick(View view) {
String url=[Link]().toString();
Intent intent = new Intent(Intent.ACTION_VIEW, [Link](url));
startActivity(intent);
}
});
}
}

Output :
Practical : 10
Aim: To Design UI of LDRP logo and title screen using Constraint Layout.
(Use Vertical and Horizontal Guidelines)

CODE:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#C881D5"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginTop="60dp"
android:src="@drawable/ldrp_805"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="LDRP-ITR"
android:textSize="28sp"
app:layout_constraintEnd_toStartOf="@+id/guideline8"
app:layout_constraintStart_toStartOf="@+id/guideline7"
app:layout_constraintTop_toBottomOf="@+id/imageView" />

<Button
android:id="@+id/button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:text="Log in"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:text="Sign up"
app:layout_constraintBottom_toTopOf="@+id/button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<[Link]
android:id="@+id/guideline7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="20dp" />

<[Link]
android:id="@+id/guideline8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_end="20dp" />

<[Link]
android:id="@+id/guideline5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="20dp" />

<[Link]
android:id="@+id/guideline6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_end="20dp" />

<[Link]
android:id="@+id/guideline9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="20dp"
app:layout_constraintGuide_percent="0.75" />
</[Link]>

[Link]
package [Link].practical10;
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
}

Output:
Practical : 11
Aim: Create an Android App to implement checkbox and radio button.

CODE:
activity_main.xml
<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="@+id/tvRg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="Select The Subject"
android:textAppearance="?android:attr/textAppearanceMedium" />

<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tvRg"
android:layout_centerHorizontal="true"
android:orientation="horizontal"
android:showDividers="beginning|middle|end"
android:layout_marginTop="10dp"
android:id="@+id/radioGroup" >
<RadioButton
android:id="@+id/rb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Maths"
android:checked="false" />
<RadioButton
android:id="@+id/rb2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Chemistry"
android:checked="true" />
<RadioButton
android:id="@+id/rb3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Physics"
android:checked="false" />
</RadioGroup>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SUBMIT"
android:id="@+id/btnSubmit"
android:layout_below="@+id/radioGroup"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"/>
<TextView
android:id="@+id/tvCb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/radioGroup"
android:gravity="center"
android:text="Give Your Ratings Here."
android:layout_marginTop="65dp"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Excellent"
android:id="@+id/cb1"
android:layout_below="@+id/tvCb"
android:layout_centerHorizontal="true"
android:checked="false"/>
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Good"
android:id="@+id/cb2"
android:layout_below="@+id/cb1"
android:layout_centerHorizontal="true"
android:checked="false"/>
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Okay"
android:id="@+id/cb3"
android:layout_below="@+id/cb2"
android:layout_centerHorizontal="true"
android:checked="false"/>
</RelativeLayout>

[Link]
package [Link].practical11;
import [Link];
//import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


// These are the global variables
RadioGroup radioGroup;
RadioButton selectedRadioButton;
Button buttonSubmit;
CheckBox cb1, cb2, cb3;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
// layout instances
buttonSubmit = (Button) findViewById([Link]);
radioGroup = (RadioGroup) findViewById([Link]);
cb1 = (CheckBox) findViewById([Link].cb1);
cb2 = (CheckBox) findViewById([Link].cb2);
cb3 = (CheckBox) findViewById([Link].cb3);
[Link](new [Link]() {

@Override
public void onClick(View v) {
// get the selected RadioButton of the group
selectedRadioButton =
(RadioButton)findViewById([Link]());
//get RadioButton text
String yourVote = [Link]().toString();
// display it as Toast to the user
[Link]([Link], "Selected Radio Button is:" + yourVote ,
Toast.LENGTH_LONG).show();
}
});
[Link](new [Link]() {

@Override
public void onClick(View v) {
//Get the selected RadioButton
selectedRadioButton = (RadioButton)
findViewById([Link]());
// get RadioButton text
String yourVote = [Link]().toString();
String checkBoxChoices = "";
if ([Link]()) {
checkBoxChoices += [Link]().toString() + "\tYES";
}
else{
checkBoxChoices += [Link]().toString() + "\tNO";
}
if ([Link]()) {
checkBoxChoices += [Link]().toString() + "\tYES";
}
else{
checkBoxChoices += [Link]().toString() + "\tNO";
}
if ([Link]()) {
checkBoxChoices += [Link]().toString() + "\tYES";
}
else{
checkBoxChoices += [Link]().toString() + "\tNO";
}
[Link]([Link], "Selected Radio Button is:" + yourVote + "\n
CheckBox Choices: \n "+ checkBoxChoices , Toast.LENGTH_LONG).show();
}
});
}
}

OUTPUT:
Practical : 12
Aim: Create an Android App to implement SeekBar and menu.

CODE:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:max="100" />

<TextView
android:id="@+id/seekBarValueTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/seekBar"
android:layout_centerHorizontal="true"
android:paddingTop="16dp"
android:text="SeekBar Value: 0"
android:textSize="18sp" />
</RelativeLayout>

menu_main.xml
<menu xmlns:android="[Link]
<item
android:id="@+id/menu_item1"
android:title="Menu Item 1" />
<item
android:id="@+id/menu_item2"
android:title="Menu Item 2" />
<item
android:id="@+id/menu_item3"
android:title="Menu Item 3" />
</menu>

[Link]
package [Link].practical12;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

private TextView seekBarValueTextView;


@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
// Initialize views
seekBarValueTextView = findViewById([Link]);
SeekBar seekBar = findViewById([Link]);

// SeekBar listener
[Link](new [Link]() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// Update TextView with SeekBar value
[Link]("SeekBar Value: " + progress);
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate([Link].menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = [Link]();
switch (id) {
case [Link].menu_item1:
// Handle action for menu item 1
return true;
case [Link].menu_item2:
// Handle action for menu item 2
return true;
case [Link].menu_item3:
// Handle action for menu item 3
return true;
default:
return [Link](item);
}
}
}

OUTPUT:
Practical : 13
Aim: To implement Splash screen(Welcome Screen) with animation in
android.

CODE:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
tools:context=".MainActivity">

<!-- THIS IS SIMPLE TEXTVIEW-->


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome To Home"
android:textColor="#EA0909"
android:textSize="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</[Link]>

Side_slide.xml
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="[Link]

<!--THIS CODE IS FOR SIDE ANIMATION-->


<translate
android:duration="1500"
android:fromXDelta="-50%"
android:fromYDelta="0%" />

<alpha
android:duration="1500"
android:fromAlpha="0.1"
android:toAlpha="1.0" />
</set>

activity_splash_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
tools:context=".SplashScreen">

<!--THIS IS IMAGEVIEW FOR OUR IMAGE IN SPLASH SCREEN-->


<!--YOU CAN ADD YOUR IMAGE TO DRAWABLES.-->
<ImageView
android:id="@+id/SplashScreenImage"
android:layout_width="300dp"
android:layout_height="200dp"
android:src="@drawable/icon"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</[Link]>

[Link]
package [Link].practical13;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

@SuppressWarnings("deprecation")
public class SplashScreen extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_splash_screen);
// This is used to hide the status bar and make
// the splash screen as a full screen activity.
getWindow().setFlags(
[Link].FLAG_FULLSCREEN,
[Link].FLAG_FULLSCREEN
);
// HERE WE ARE TAKING THE REFERENCE OF OUR IMAGE
// SO THAT WE CAN PERFORM ANIMATION USING THAT IMAGE
ImageView backgroundImage = findViewById([Link]);
[Link] slideAnimation =
[Link](this, [Link].side_slide);
[Link](slideAnimation);
// we used the postDelayed(Runnable, time) method
// to send a message with a delayed time.
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent([Link], [Link]);
startActivity(intent);
finish();
}
}, 3000); // 3000 is the delayed time in milliseconds.
}
}
OUTPUT:
Practical : 14
Aim: Create an Android App to implement Change language (Eng to Hindi)

CODE:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

xmlns:android="[Link]

xmlns:app="[Link]

xmlns:tools="[Link]

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

tools:context=".MainActivity">

<!--text view for the message to display-->

<TextView

android:id="@+id/textView"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_margin="48dp"

android:text="Change The Language"

android:textSize="25sp"

android:textAlignment="center" />

<!--button view for hindi language-->

<Button

android:id="@+id/btnHindi"

android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:layout_margin="16dp"

android:background="@color/colorPrimary"

android:text="Hindi"

android:textSize="25sp"

android:textColor="#212121" />

<!--button view for english language-->

<Button

android:id="@+id/btnEnglish"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_margin="16dp"

android:background="@color/colorPrimary"

android:text="English"

android:textSize="25sp"
android:textColor="#212121" />

</LinearLayout>

[Link]
package [Link].practical14;

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
TextView messageView;
Button btnHindi, btnEnglish;
Context context;
Resources resources;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

// referencing the text and button views


messageView = (TextView) findViewById([Link]);
btnHindi = findViewById([Link]);
btnEnglish = findViewById([Link]);

// setting up on click listener event over the button


// in order to change the language with the help of
// LocaleHelper class
[Link](new [Link]() {
@Override
public void onClick(View view) {
context = [Link]([Link], "en");
resources = [Link]();
[Link]([Link]([Link]));
}
});

[Link](new [Link]() {
@Override
public void onClick(View view) {
context = [Link]([Link], "hi");
resources = [Link]();
[Link]([Link]([Link]));
}
});

}
}

[Link]
package [Link].practical14;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];

class LocaleHelper {
private static final String SELECTED_LANGUAGE =
"[Link]";

// the method is used to set the language at runtime


public static Context setLocale(Context context, String language) {
persist(context, language);

// updating the language for devices above android nougat


if ([Link].SDK_INT >= Build.VERSION_CODES.N) {
return updateResources(context, language);
}
// for devices having lower version of android os
return updateResourcesLegacy(context, language);
}

private static void persist(Context context, String language) {


SharedPreferences preferences =
[Link](context);
[Link] editor = [Link]();
[Link](SELECTED_LANGUAGE, language);
[Link]();
}

// the method is used update the language of application by creating


// object of inbuilt Locale class and passing language argument to it
@TargetApi(Build.VERSION_CODES.N)
private static Context updateResources(Context context, String language) {
Locale locale = new Locale(language);
[Link](locale);

Configuration configuration = [Link]().getConfiguration();


[Link](locale);
[Link](locale);

return [Link](configuration);
}

@SuppressWarnings("deprecation")
private static Context updateResourcesLegacy(Context context, String language) {
Locale locale = new Locale(language);
[Link](locale);

Resources resources = [Link]();

Configuration configuration = [Link]();


[Link] = locale;
if ([Link].SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
[Link](locale);
}

[Link](configuration, [Link]());

return context;
}
}

values\[Link]
<resources>
<string name="app_name">Practical 14</string>
<string name="selected_language">English</string>
<string name="language">Hello</string>
</resources>

Hi-Rin\[Link]
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">GFG | Change App Language</string>

<string name="selected_language">हि न्दी</string>

<string name="language">नमस्ते </string>


</resources>

OUTPUT :
Practical : 15
Aim: Create an Android App to implement Shared Preference.

CODE:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:ignore="HardcodedText">

<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp"
android:text="Shared Preferences Demo"
android:textColor="@android:color/black"
android:textSize="24sp" />

<!--EditText to take the data from the user and save the data in SharedPreferences-->
<EditText
android:id="@+id/edit1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textview"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:hint="Enter your Name"
android:minHeight="48dp"
android:padding="10dp" />

<!--EditText to take the data from the user and save the data in SharedPreferences-->
<EditText
android:id="@+id/edit2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/edit1"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:hint="Enter your Age"
android:inputType="number"
android:minHeight="48dp"
android:padding="10dp" />
</RelativeLayout>

[Link]
package [Link].practical15;

import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


private EditText name, age;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
name = findViewById([Link].edit1);
age = findViewById([Link].edit2);
}

// Fetch the stored data in onResume() Because this is what will be called when the app
opens again
@Override
protected void onResume() {
[Link]();
// Fetching the stored data from the SharedPreference
SharedPreferences sh = getSharedPreferences("MySharedPref", MODE_PRIVATE);
String s1 = [Link]("name", "");
int a = [Link]("age", 0);

// Setting the fetched data in the EditTexts


[Link](s1);
[Link]([Link](a));
}

// Store the data in the SharedPreference in the onPause() method


// When the user closes the application onPause() will be called and data will be stored
@Override
protected void onPause() {
[Link]();
// Creating a shared pref object with a file name "MySharedPref" in private mode
SharedPreferences sharedPreferences = getSharedPreferences("MySharedPref",
MODE_PRIVATE);
[Link] myEdit = [Link]();

// write all the data entered by the user in SharedPreference and apply
[Link]("name", [Link]().toString());
[Link]("age", [Link]([Link]().toString()));
[Link]();
}
}

OUTPUT :
Practical : 16
Aim: Create an Android App to display student details in List View (using
Adapter class).

CODE:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<ListView
android:id="@+id/simpleListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="@color/material_blue_grey_800"
android:dividerHeight="1dp" />
</LinearLayout>

Activity_listview.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:id="@+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"

android:paddingBottom="20dp"
android:textColor="@color/black" />
</LinearLayout>

[Link]
package [Link].practical16;
import [Link];
import [Link];
import [Link];
import [Link];import [Link];

public class MainActivity extends Activity


{
// Array of strings...
ListView simpleList;
String countryList[] = {"India", "China", "australia", "Portugle", "America",
"NewZealand"};

@Override protected void onCreate(Bundle savedInstanceState) {


[Link](savedInstanceState); setContentView([Link].activity_main);
simpleList = (ListView)findViewById([Link]);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,
[Link].activity_listview, [Link], countryList);
[Link](arrayAdapter);
}
}
OUTPUT:
Practical : 17
Aim: To implement Web View in android application.
CODE:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!-- unique ID of WebView -->
<WebView
android:id="@+id/web"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp" />
</RelativeLayout>

[Link]
package [Link].practical17;
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
// Find the WebView by its unique ID
WebView webView = findViewById([Link]);
// loading [Link] url in the WebView.
[Link]("[Link]
// this will enable the javascript.
[Link]().setJavaScriptEnabled(true);
// WebViewClient allows you to handle
// onPageFinished and override Url loading.
[Link](new WebViewClient());
}
}

[Link]
<uses-permission android:name="[Link]" />
OUTPUT :
Practical : 18
Aim: Create an Android App to implement CRUD operation using SqLite
Database.
CODE:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<EditText
android:id="@+id/fname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="First Name"
android:inputType="text" />

<EditText
android:id="@+id/lname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Last Name"
android:inputType="text" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<Button
android:id="@+id/submit_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="SUBMIT" />

<Button
android:id="@+id/edit_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="EDIT"
android:visibility="gone" />

<Button
android:id="@+id/display_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="DISPLAY" />
</LinearLayout>
</LinearLayout>
[Link]
package [Link].practical18;

import [Link];
import [Link];
import [Link];

import [Link];

public class DBmain extends SQLiteOpenHelper {


private static final String DBNAME = "student";
private static final String TABLE = "subject";
private static final int VER = 1;

public DBmain(@Nullable Context context) {


super(context, DBNAME, null, VER);
}

@Override
public void onCreate(SQLiteDatabase db) {
String query = "create table " + TABLE + "(id integer primary key, fname text, lname
text)";
[Link](query);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
String query = "drop table if exists " + TABLE + "";
[Link](query);
onCreate(db);
}
}
[Link]
package [Link].practical18;
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


DBmain dBmain;
SQLiteDatabase sqLiteDatabase;
EditText lname, fname;
Button submit, display, edit;
int id = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

dBmain = new DBmain(this);


//create object
findid();
insertData();
cleardata();
editdata();
}
private void editdata() {
if (getIntent().getBundleExtra("studata") != null) {
Bundle bundle = getIntent().getBundleExtra("studata");
id = [Link]("id");
[Link]([Link]("fname"));
[Link]([Link]("lname"));

[Link]([Link]);
[Link]([Link]);
}
}

private void cleardata() {


[Link]("");
[Link]("");
}

private void insertData() {


[Link](new [Link]() {
@Override
public void onClick(View v) {
ContentValues contentValues = new ContentValues();
[Link]("fname", [Link]().toString().trim());
[Link]("lname", [Link]().toString().trim());

sqLiteDatabase = [Link]();
Long recid = [Link]("subject", null, contentValues);
if (recid != null) {
[Link]([Link], "successfully insert",
Toast.LENGTH_SHORT).show();
cleardata();
} else {
[Link]([Link], "something wrong try again",
Toast.LENGTH_SHORT).show();
}
}
});
[Link](new [Link]() {
@Override
public void onClick(View v) {
Intent intent = new Intent([Link], [Link]);
startActivity(intent);
}
});
[Link](new [Link]() {
@Override
public void onClick(View v) {
ContentValues contentValues = new ContentValues();
[Link]("fname", [Link]().toString().trim());
[Link]("lname", [Link]().toString().trim());

sqLiteDatabase = [Link]();
long recid = [Link]("subject", contentValues, "id=" + id, null);
if (recid != -1) {
[Link]([Link], "Update successfully",
Toast.LENGTH_SHORT).show();
[Link]([Link]);
[Link]([Link]);
cleardata();
} else {
[Link]([Link], "something wrong try again",
Toast.LENGTH_SHORT).show();
}
}
});
}

private void findid() {


fname = (EditText) findViewById([Link]);
lname = (EditText) findViewById([Link]);
submit = (Button) findViewById([Link].submit_btn);
display = (Button) findViewById([Link].display_btn);
edit = (Button) findViewById([Link].edit_btn);
}
}
Activity_main2.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity2">
<ListView
android:divider="#E6DCCE"
android:dividerHeight="1dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lv"/>
</LinearLayout>
[Link]
package [Link].practical18;

import [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];

public class MainActivity2 extends AppCompatActivity {


DBmain dBmain;
SQLiteDatabase sqLiteDatabase;
String[] fname, lname;
int[] id;
ListView lv;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main2);
dBmain = new DBmain(this);
findid();
displaydata();

private void displaydata() {


sqLiteDatabase = [Link]();
Cursor cursor = [Link]("select *from subject", null);
if ([Link]() > 0) {
id = new int[[Link]()];
fname = new String[[Link]()];
lname = new String[[Link]()];
int i = 0;

while ([Link]()) {
id[i] = [Link](0);
fname[i] = [Link](1);
lname[i] = [Link](2);
i++;
}
CustAdapter custAdapter = new CustAdapter();
[Link](custAdapter);
}
}

private void findid() {


lv = (ListView) findViewById([Link]);
}

private class CustAdapter extends BaseAdapter {


@Override
public int getCount() {
return [Link];
}

@Override
public Object getItem(int position) {
return null;
}

@Override
public long getItemId(int position) {
return 0;
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
TextView txtfname, txtlname;
ImageButton txt_edit, txt_delete;
CardView cardview;
convertView = [Link]([Link]).inflate([Link],
parent, false);
txtfname = [Link]([Link].txt_fname);
txtlname = [Link]([Link].txt_lname);
txt_edit = [Link]([Link].txt_edti);
txt_delete = [Link]([Link].txt_delete);
cardview = [Link]([Link]);
[Link](new [Link]() {
@Override
public void onClick(View v) {
//background random color
Random random = new Random();
[Link]([Link](255, [Link](256),
[Link](256), [Link](256)));
txt_delete.setVisibility([Link]);
txt_edit.setVisibility([Link]);
[Link]([Link]);
[Link]([Link]);
}
});
[Link](fname[position]);
[Link](lname[position]);
txt_edit.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
Bundle bundle = new Bundle();
[Link]("id", id[position]);
[Link]("fname", fname[position]);
[Link]("lname", lname[position]);
Intent intent = new Intent([Link], [Link]);
[Link]("studata", bundle);
startActivity(intent);
}
});
txt_delete.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
sqLiteDatabase = [Link]();
long recremove = [Link]("subject", "id=" + id[position], null);
if (recremove != -1) {
[Link]([Link], "successfully delete",
Toast.LENGTH_SHORT).show();
startActivity(new Intent([Link], [Link]));
displaydata();
}
}
});
return convertView;
}
}
}
[Link]
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="12dp"
app:cardElevation="8dp"
android:id="@+id/cardview"
app:cardMaxElevation="8dp"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp">
<TextView
android:visibility="visible"
android:id="@+id/txt_fname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="textfname" />

<TextView
android:visibility="visible"
android:id="@+id/txt_lname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:gravity="center"
android:text="textlname" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/txt_lname"
android:orientation="horizontal">

<ImageButton
android:background="@null"
android:layout_weight="1"
android:visibility="gone"
android:id="@+id/txt_edti"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_baseline_edit_24"/>

<ImageButton
android:visibility="gone"
android:background="@null"
android:src="@drawable/ic_baseline_delete_24"
android:id="@+id/txt_delete"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</LinearLayout>
</RelativeLayout>
</[Link]>
OUTPUT :
Practical : 19
Aim: Create an Android App to implement Recycler View.
CODE:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/recycler_view"/>

</FrameLayout>
[Link]
package [Link].practical19;

import [Link];
import [Link];
import [Link];
import [Link];

import [Link];

import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

RecyclerView recyclerView = findViewById([Link].recycler_view);

[Link](new LinearLayoutManager(this));
[Link](new CustomAdapter(generateData()));
[Link](new DividerItemDecoration(this,
[Link]));
}

private List<String> generateData() {


List<String> data = new ArrayList<>();
for (int i = 0; i < 10; i++) {
[Link]([Link](i) + "th Element");
}
return data;
}

}
list_item_view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="46dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textview"
android:text="TextView"
android:textSize="16dp" />

</LinearLayout>
[Link]
package [Link].practical19;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];

import [Link];

public class CustomAdapter extends [Link]<[Link]> {


private List<String> data;
public CustomAdapter (List<String> data){
[Link] = data;
}

@Override
public [Link] onCreateViewHolder(ViewGroup parent, int
viewType) {
View rowItem =
[Link]([Link]()).inflate([Link].list_item_view, parent, false);
return new ViewHolder(rowItem);
}

@Override
public void onBindViewHolder([Link] holder, int position) {
[Link]([Link](position));
}

@Override
public int getItemCount() {
return [Link]();
}

public static class ViewHolder extends [Link] implements


[Link] {
private TextView textView;

public ViewHolder(View view) {


super(view);
[Link](this);
[Link] = [Link]([Link]);
}

@Override
public void onClick(View view) {
[Link]([Link](), "position : " + getLayoutPosition() + " text : " +
[Link](), Toast.LENGTH_SHORT).show();
}
}
}
OUTPUT:

You might also like