Android 50
Android 50
Date :
Procedure :
2. Follow the setup wizard’s instructions to install Android Studio on your computer.
3. Choose the installation location and add any additional components you want to
install (such as Android Virtual Device)
5. Review the installation settings and click “Install” to begin the installation process.
6. Wait for the installation to complete. This may take some time depending on your
system specifications.
2. On the welcome screen, click “Configure” and the select “SDK Manager”.
3. In the SDK Manager, install the necessary SDK components for the Android versions
you intend to target.
5. Specify the location of the Android SDK by clicking on the “SDK Location” field and
browsing to the SDK directory.
1. To test your apps, you can set up an android emulator by clicking on “Configure”>”AVD
Manager”.
3. Choose a hardware profile and system image for the emulator and click “Next”.
4. Configure the emulator settings such as RAM size, and storage and click “Finish”.
5. Once the emulator is created, select it from the AVD Manager and click “Start” to launch
the emulator.
4. Run the project by clicking on the “Run” button (green triangle) in the toolbar.
5. If the project builds successfully and launches on the emulator or connected device,
Android Studio is installed and configured correctly.
Output :
Result:
Thus the Android Studio application has been installed successfully.
Exp No : 2
Date :
Aim :
To implement the Simple design layout in Android Studio.
Algorithm :
Xml :
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout
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=".MainActivity2">
<TextView android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="268dp"
android:layout_marginEnd="88dp"
android:text="NAME : "
android:textSize="30dp" android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="64dp" android:layout_marginTop="52dp"
android:text="RRN : "
android:textSize="30dp" android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView4" /> <ImageView
android:id="@+id/imageView" android:layout_width="wrap_content"
android:layout_height="wrap_content" app:srcCompat="@drawable/profile"
tools:layout_editor_absoluteX="56dp" tools:layout_editor_absoluteY="49dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
Java :
package com.example.myapplication; import
androidx.appcompat.app.AppCompatActivity; import android.os.Bundle;
public class MainActivity2 extends AppCompatActivity { @Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2);
}}
Output :
Result :
Thus to implement the applications to show GUI components in Android Studio have been
executed successfully.
Exp No : 3 IMPLICIT AND EXPLICIT
Date :
Aim :
To implement the implicit and explicit in Android Studio.
Algorithm :
Xml :
Activity-1
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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">
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="
page
1" tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="140dp"
tools:layout_editor_absoluteY="157dp" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text=" page
2" tools:layout_editor_absoluteX="171dp"
tools:layout_editor_absoluteY="559dp" />
<TextView android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click to go to login 2"
android:textColor="#FFC107"
android:textSize="20dp"
android:textStyle="italic" tools:layout_editor_absoluteX="87dp"
tools:layout_editor_absoluteY="442dp" />
<TextView android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click to go to page 1"
android:textColor="#FFC107"
android:textSize="20dp"
android:textStyle="italic" tools:layout_editor_absoluteX="94dp"
tools:layout_editor_absoluteY="110dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
Activity-2
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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=".MainActivity2">
<TextView android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="252dp" android:layout_marginEnd="220dp"
android:text="NAME : " android:textSize="30dp" android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="80dp"
android:layout_marginTop="84dp"
android:text="RRN : " android:textSize="30dp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id
/textView4" />
</androidx.constraintlayout.widget.ConstraintLayout>
b1 = (Button) findViewById(R.id.button); b2
= (Button) findViewById(R.id.button2);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent cs = new Intent(MainActivity.this, MainActivity2.class);
startActivity(cs);
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent cse = new Intent(Intent.ACTION_VIEW);
cse.setData(Uri.parse("https://www.youtube.com/")); startActivity(cse); }
});
}
}
Java-2 package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
Result :
Thus to implement the implicit and explicit in Android Studio have been executed
successfully.
Exp No : 4 CALCULATOR
Date :
Aim :
Algorithm :
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" 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=" CALC"
android:textStyle="bold" android:textColor="#FFEB3B" 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" />
<EditText
android:id="@+id/second_no"
android:layout_width="102dp"
android:layout_height="59dp"
android:ems="10"
android:hint="Enter" />
</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="wrap_content" android:layout_height="77dp"
android:layout_marginHorizontal="50dp" android:hint="ANSWER"
android:textSize="35sp" />
</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/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/sub"
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>
Java :
package com.example.calculartor_sr;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle; import
android.view.View; import
android.widget.Button; import
android.widget.EditText; import
android.widget.TextView; import
android.widget.Toast;
@SuppressLint("MissingInflatedId")
@Override protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String num1 = no1.getText().toString();
String num2 = no2.getText().toString();
if (num1.isEmpty() || num2.isEmpty()) {
Toast.makeText(getApplicationContext(),"Enter
Numbers",Toast.LENGTH_SHORT).show();
} else
{ double a =
Double.parseDouble(no1.getText().toString()); double b
=
Double.parseDouble(no2.getText().toString()); ans =
a + b;
}
}
});
sub.set
OnClick
Listener
(new
View.O
nClickLi
stener()
{
@Override
public void onClick(View v) {
String num1 = no1.getText().toString();
String num2 = no2.getText().toString();
if (num1.isEmpty() || num2.isEmpty()) {
Toast.makeText(getApplicationContext(),"Enter
Numbers",Toast.LENGTH_SHORT).show();
} else {
double a =
Double.parseDouble(no1.getText().toString());
double b
=
Double.parseDouble(no2.getText().toString()); ans =
a - b;
}
}
});
mul.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String num1 = no1.getText().toString();
String num2 = no2.getText().toString();
if (num1.isEmpty() || num2.isEmpty()) {
Toast.makeText(getApplicationContext(),"Enter
Numbers",Toast.LENGTH_SHORT).show();
} else
{ double a =
Double.parseDouble(no1.getText().toString()); double b
=
Double.parseDouble(no2.getText().toString()); ans =
a * b;
}
}
});
div.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String num1 = no1.getText().toString();
String num2 = no2.getText().toString();
if (num1.isEmpty() || num2.isEmpty()) {
Toast.makeText(getApplicationContext(),
"Enter Numbers", Toast.LENGTH_SHORT).show();
} else { double a
=
Double.parseDouble(no1.getText().toString()); double b
=
Double.parseDouble(no2.getText().toString()); if
(b != 0) ans = a / b;
else
Toast.makeText(getApplicationContext(), "Enter Valid Numbers",
Toast.LENGTH_SHORT).show();
}
}
});
equal.setOnClickListener(new View.OnClickListener() {
@Override public void
onClick(View v) {
String ans1 = String.valueOf(ans);
answer.setText(ans1);
ans= 0;
}
});
}}
Output :
Result :
Thus to implement calculator in Android Studio have been executed successfully.
Exp No : 5
Date :
Aim :
To implement scroll bar in Android Studio.
Algorithm :
Xml :
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout
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">
<TextView android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_marginTop="16dp"
android:text="Vertical ScrollView"
android:textColor="#304FFE" android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ScrollView android:id="@+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="250dp" android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2">
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content" android:orientation="vertical">
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#F4E599" android:padding="10dp"
android:text="string/This"
android:textSize="24sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#F4E599"
android:padding="10dp" android:text="@string/is"
android:textSize="24sp" />
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#F4E599"
android:padding="10dp"
android:text="@string/a" android:textSize="24sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#F4E599"
android:padding="10dp" android:text="@string/vertical"
android:textSize="24sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_marginTop="10dp"
android:background="#F4E599" android:padding="10dp"
android:text="@string/scrollview"
android:textSize="24sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content" android:background="#F4E599"
android:padding="10dp" android:text="@string/This"
android:textSize="24sp" />
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" android:background="#F4E599"
android:padding="10dp"
android:text="@string/is" android:textSize="24sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#F4E599"
android:padding="10dp" android:text="@string/a"
android:textSize="24sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#F4E599"
android:padding="10dp" android:text="@string/vertical"
android:textSize="24sp" />
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#F4E599"
android:padding="10dp"
android:text="@string/scrollview"
android:textSize="24sp" />
</LinearLayout>
</ScrollView>
<HorizontalScrollView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView127">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#5BBAF5"
android:padding="10dp" android:text="@string/This"
android:textSize="24sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:background="#5BBAF5"
android:padding="10dp" android:text="@string/is" android:textSize="24sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:background="#5BBAF5" android:padding="10dp"
android:text="@string/a" android:textSize="24sp" />
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="10dp" android:background="#5BBAF5"
android:padding="10dp" android:text="@string/horizontal"
android:textSize="24sp" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp" android:background="#5BBAF5"
android:padding="10dp"
android:text="@string/scrollview"
android:textSize="24sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#5BBAF5"
android:padding="10dp" android:text="@string/This"
android:textSize="24sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:background="#5BBAF5"
android:padding="10dp" android:text="@string/is"
android:textSize="24sp" />
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="10dp" android:background="#5BBAF5"
android:padding="10dp" android:text="@string/a"
android:textSize="24sp" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:background="#5BBAF5"
android:padding="10dp"
android:text="@string/horizontal"
android:textSize="24sp" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:background="#5BBAF5"
android:padding="10dp"
android:text="@string/scrollview"
android:textSize="24sp" />
</LinearLayout>
Java:
package com.example.scrollbar033;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
Result : Thus to implement scroll bar in Android Studio have been executed successfully.
Exp No : 6
Implementation of Rating Bar
Date :
Aim :
To implement rating bar in Android studio.
Algorithm :
Xml :
<!-- res/layout/activity_main.xml -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity">
<RatingBar android:id="@+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:numStars="5" android:rating="2.5"
android:stepSize="0.5"/>
<Button
android:id="@+id/btnSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/ratingBar"
android:layout_centerHorizontal="true" android:layout_marginTop="16dp"
android:text="Submit Rating"/>
<TextView
android:id="@+id/textRating"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/btnSubmit"
android:layout_centerHorizontal="true" android:layout_marginTop="16dp"
android:text="Rating: N/A"/> </RelativeLayout> Java
:
package com.example.ratingapp;
RatingBar ratingBar;
Button btnSubmit;
TextView textRating;
@Override protected void onCreate(Bundle
savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnSubmit.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) { float
currentRating = ratingBar.getRating();
textRating.setText("Rating:
" + currentRating);
Toast.makeText(MainActivity.this, "Submitted Rating: " + currentRating,
Toast.LENGTH_SHORT).show();
}
});
ratingBar.setOnRatingBarChangeListener(new
RatingBar.OnRatingBarChangeListener() {
@Override public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
// Update the rating as the user changes it textRating.setText("Rating:
" + rating);
}
});
}}
Output :
Result :
Thus to implement the rating app in Android Studio have been executed successfully.
Exp No : 7
Display of Toast Message
Date :
Aim :
To implement Display of Toast Message in Android Studio.
Algorithm :
Xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" tools:context=".MainActivity">
<Button
android:id="@+id/btnShowToast" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Show
Toast" android:layout_centerInParent="true"/>
</RelativeLayout> Java
:
package com.example.myapplication; // Replace this with your package name
android.view.View; import
Result :
Thus to implement toggle button in Android Studio have been executed successfully.
Exp No : 8 IMPLEMENTATION OF TOGGLE BUTTON
Date :
Aim :
To implement toggle button in Android Studio.
Algorithm :
Xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">
<ToggleButton android:id="@+id/toggleButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="150dp"
android:layout_marginLeft="150dp"
android:text="Toggle 1" />
<ToggleButton android:id="@+id/toggleButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toggle 2"
android:layout_below="@id/toggleButton1"
android:layout_marginTop="50dp" android:layout_marginLeft="150dp"
android:layout_centerHorizontal="true"/>
<TextView
android:id="@+id/outputTextView"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/toggleButton2"
android:layout_marginTop="16dp" android:layout_centerHorizontal="true"/>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_marginTop="75dp"
android:layout_marginLeft="130dp"
android:textStyle="bold"
android:textSize="30dp" android:text="Toggle
Button" />
<ImageView android:id="@+id/imageView"
android:layout_width="180dp"
android:layout_height="122dp"
android:layout_marginLeft="110dp"
android:layout_marginTop="450dp"
app:srcCompat="@drawable/toggle" />
</RelativeLayout>
Java :
package com.example.togglebtn033;
toggleButton1.setOnCheckedChangeListener(new
CompoundButton.OnCheckedChangeListener() {
@Override public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) { updateOutputText();
}
});
toggleButton2.setOnCheckedChangeListener(new
CompoundButton.OnCheckedChangeListener() {
@Override public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) { updateOutputText();
}
});
}
outputTextView.setText(stringBuilder.toString());
}
}
Output :
Result :
Thus to implement toggle button in Android Studio have been executed successfully.
Exp No : 9 IMPLEMENTATION OF CHECK BOX
Date :
Aim :
To implement check box in Android Studio.
Algorithm :
Xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent"
android:padding="16dp"
tools:context=".MainActivity">
<CheckBox android:id="@+id/checkboxOption1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="150dp"
android:layout_marginTop="150dp"
android:checked="false" android:text="Java" />
<CheckBox android:id="@+id/checkboxOption2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="150dp"
android:text="Kotlin" android:checked="false"
android:layout_below="@id/checkboxOption1"
android:layout_marginTop="16dp"/>
<CheckBox android:id="@+id/checkboxOption3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="150dp"
android:text="Swift" android:checked="false"
android:layout_below="@id/checkboxOption2"
android:layout_marginTop="16dp"/>
<Button android:id="@+id/submit_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="150dp"
android:text="Submit"
android:backgroundTint="#D32626"
android:textStyle="bold"
android:layout_below="@id/checkboxOption3" android:layout_marginTop="16dp"/>
<TextView android:id="@+id/textView"
android:layout_width="221dp"
android:layout_height="69dp"
android:layout_marginLeft="110dp"
android:layout_marginTop="70dp"
android:text=" Checkbox"
android:textAlignment="center"
android:textColor="@color/black"
android:textSize="25sp"
android:textStyle="bold" />
</RelativeLayout>
Java :
import android.os.Bundle; import android.view.View; import
android.widget.Button; import android.widget.CheckBox;
import android.widget.Toast; import
androidx.appcompat.app.AppCompatActivity; public class
MainActivity extends AppCompatActivity {
private CheckBox checkboxOption1, checkboxOption2, checkboxOption3; private Button
submitButton;
submitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
StringBuilder message = new StringBuilder("Selected options: ");
if (checkboxOption1.isChecked()) {
message.append("Option 1, ");
}
if (checkboxOption2.isChecked()) {
message.append("Option 2, ");
}
if (checkboxOption3.isChecked()) { message.append("Option 3");
}
// Remove the trailing comma and space if
(message.charAt(message.length() - 2) == ',') {
message.delete(message.length() - 2, message.length());
}
Toast.makeText(MainActivity.this, message.toString(),
Toast.LENGTH_SHORT).show();
}
});
}}
Output :
Result :
Thus to implement check box in Android Studio have been executed successfully.
Exp No : 10 IMPLEMENTATION OF ANIMATION
Date :
Aim :
To implement animation in Android Studio.
Algorithm :
Xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity">
<Button android:id="@+id/btnAnimate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" android:layout_marginTop="20dp"
android:text="Animate" />
<ImageView android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/btnAnimate"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:src="@drawable/ic_launcher_foreground" />
</RelativeLayout>
Java:
package com.example.animation_md;
import androidx.appcompat.app.AppCompatActivity;
rotateAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override public void onAnimationStart(Animation
animation) {}
@Override
public void onAnimationEnd(Animation animation) {
animateAntiClockwise();
}
@Override
public void onAnimationRepeat(Animation animation) {}
});
}
Result :
Thus to implement animation in Android Studio have been executed successfully.
Exp No : 11 FRAGMENT (MULTI-THREADING)
Date :
Aim :
To implement Fragments in Android Studio.
Algorithm :
Xml :
<?xml version="1.0" encoding="utf8"?>
<RelativeLayout xmlns:android="http:
//schemas.android.c
om/apk/res/android"
xmlns:tools="http://s
chemas.android.co
m/tools"
android:layout_widt h="match_parent"
android:layout_heig ht="match_parent"
tools:context=".Main Activity">
<FrameLayout
android:id="@+id/fra gmentContainer"
android:layout_widt h="match_parent"
android:layout_heig ht="match_parent"
android:layout_abov
e="@+id/buttonCont
ainer"
android:layout_align ParentTop="true"
/>
android:layout_widt h="match_parent"
android:layout_heig ht="wrap_content"
android:layout_align ParentBottom="true"
android:orientation= "horizontal">
<Button
android:id="@+id/bt
nFragment1"
android:layout_widt h="0dp"
android:layout_heig ht="wrap_content"
android:layout_weig ht="1"
android:text="Fragm ent
1" />
<Button
android:id="@+id/bt nFragment2"
android:layout_widt h="0dp"
android:layout_heig ht="wrap_content"
android:layout_weig ht="1"
android:text="Fragm
ent 2" />
</LinearLayout>
</RelativeLayout> fragment_one.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://
schemas.android.com
/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height ="match_parent"
android:gravity="cente
r"
android:orientation="v ertical">
<TextView
android:layout_width= "wrap_content"
android:layout_height ="wrap_content"
android:text="Fragme nt 1"
android:textSize="24s p"
/>
</LinearLayout>
fragment_two.xml:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fragment 2"
android:textSize="24sp" />
</LinearLayout>
FragmentOne.java:
package com.example.myapplication;
import android.os.Bundle; import
android.view.LayoutInflater; import
android.view.View; import
android.view.ViewGroup;
import androidx.fragment.app.Fragment;
public FragmentOne() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_one, container, false);
}
}
FragmentTwo.java:
package com.example.myapplication;
public FragmentTwo() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_two, container, false);
}
}
MainActivity.java:
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment; import
androidx.fragment.app.FragmentManager; import
androidx.fragment.app.FragmentTransaction; import
android.os.Bundle; import android.view.View;
import android.widget.Button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnFragment1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loadFragment(new FragmentOne());
}
});
btnFragment2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loadFragment(new FragmentTwo());
}
});
}
Result :
Thus to implement animation in Android Studio have been executed successfully.
Exp No : 12 RSS FEEDS
Date :
Aim :
To implement RSS Feeds in Android Studio.
Algorithm :
Activity_main.xml:
<Button
android:id="@+id/btnRediff"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="101dp"
android:text="REDIFF RSS FEED" />
<Button
android:id="@+id/btnCinemaBlend"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btnRediff"
android:layout_alignParentBottom="true"
android:layout_alignStart="@+id/btnRediff"
android:layout_marginBottom="28dp" android:text="CINEMA
BLEND RSS FEED" />
</RelativeLayout>
MainActivity.java:
package example.javatpoint.com.androidrssfeed;
import android.support.v7.app.AppCompatActivity; import
android.os.Bundle; import
android.content.Intent; import android.view.View;
import android.widget.Button; import
java.util.ArrayList;
rss_item_list_row.xml:
<TextView android:id="@+id/page_url"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
<TextView
android:id="@+id/title" android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="1dip"
android:textColor="#212121" android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/pub_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/title"
android:paddingBottom="3dip"
android:textColor="#9b737775" android:textSize="14sp"
/>
</RelativeLayout>
RSSItem.java
package example.javatpoint.com.androidrssfeed;
RSSParser.java:
package example.javatpoint.com.androidrssfeed;
public RSSParser() {
}
rss_feed_xml = this.getXmlFromUrl(rss_url);
if (rss_feed_xml != null) { try {
Document doc = this.getDomElement(rss_feed_xml);
NodeList nodeList = doc.getElementsByTagName(TAG_CHANNEL);
Element e = (Element) nodeList.item(0);
activity_rssfeed.xml:
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:dividerHeight="1dp" />
</RelativeLayout>
RSSFeedActivity.java:
package example.javatpoint.com.androidrssfeed;
import android.app.ListActivity;
import android.content.Intent; import
android.os.AsyncTask; import
android.os.Bundle; import
android.view.View; import
android.widget.AdapterView; import
android.widget.ListAdapter; import
android.widget.ListView; import
android.widget.ProgressBar; import
android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rssfeed);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent in = new Intent(getApplicationContext(), WebActivity.class);
String page_url = ((TextView)
view.findViewById(R.id.page_url)).getText().toString().trim();
in.putExtra("url", page_url);
startActivity(in);
}
});
}
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
pDialog.setLayoutParams(layoutParams);
pDialog.setVisibility(View.VISIBLE);
relativeLayout.addView(pDialog);
}
@Override
protected String doInBackground(String... args) {
// rss link url
String rss_url = args[0];
// list of rss items
rssItems = rssParser.getRSSFeedItems(rss_url);
// looping through each item for
(final RSSItem item : rssItems) {
// creating new HashMap if
(item.link.toString().equals(""))
break; HashMap<String,
String> map = new HashMap<String,
String>();
map.put(TAG_TITLE, item.title);
map.put(TAG_LINK, item.link);
map.put(TAG_PUB_DATE, item.pubdate);
// adding HashList to ArrayList
rssItemList.add(map);
}
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
ListAdapter adapter = new SimpleAdapter(
RSSFeedActivity.this,
rssItemList, R.layout.rss_item_list_row,
new String[]{TAG_LINK, TAG_TITLE, TAG_PUB_DATE},
new int[]{R.id.page_url, R.id.title, R.id.pub_date});
// updating listview
setListAdapter(adapter);
}
});
return null;
}
activity_web.xml:
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.NestedScrollView>
</RelativeLayout> WebActivity.java
package example.javatpoint.com.androidrssfeed;
import android.content.Context;
import android.content.Intent; import
android.graphics.Bitmap; import
android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils; import
android.webkit.WebChromeClient; import
android.webkit.WebResourceError; import
android.webkit.WebResourceRequest;
import android.webkit.WebView; import
android.webkit.WebViewClient; import
android.widget.Toast;
WebView webView;
String url;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web); Intent in = getIntent(); url =
in.getStringExtra("url"); if (TextUtils.isEmpty(url)) {
Toast.makeText(getApplicationContext(), "URL not found",
Toast.LENGTH_SHORT).show();
finish();
}
webView = findViewById(R.id.webView);
initWebView(); webView.loadUrl(url);
}
RESULT:
Date :
Aim :
To implement Database Connection using Firebase Console in Android Studio.
Algorithm :
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent"
android:padding="16dp"
tools:context=".MainActivity">
<EditText
android:id="@+id/idEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="Enter
ID" android:layout_marginBottom="8dp"/>
<EditText
android:id="@+id/nameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Name"
android:layout_below="@id/idEditText"
android:layout_marginBottom="8dp"/>
<Button android:id="@+id/addButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Add
Data" android:layout_below="@id/nameEditText"
android:layout_marginBottom="8dp"/>
<EditText
android:id="@+id/removeIdEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter ID to Remove"
android:layout_below="@id/addButton"
android:layout_marginBottom="8dp"/>
<Button android:id="@+id/removeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Remove Data"
android:layout_below="@id/removeIdEditText"
android:layout_marginBottom="8dp"/>
<TextView android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textSize="18sp"
android:textColor="@android:color/black"
android:layout_below="@id/removeButton"/>
</RelativeLayout>
MainActivity.Java
package com.example.myguiapplication;
import androidx.appcompat.app.AppCompatActivity;
addButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String id = idEditText.getText().toString();
String name = nameEditText.getText().toString();
removeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String removeId = removeIdEditText.getText().toString();
if (!removeId.isEmpty()) { removeData(db,
Integer.parseInt(removeId));
removeIdEditText.setText(""); //
Refresh data after removal
refreshData(db);
}
}
});
DatabaseHelper.java
package com.example.myguiapplication;
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}}
Output :
Result :
Thus the program to implement database connection has been implemented
successfully
Exp No : 14 Project on Notes Application
Date :
Aim :
To create a Project on Notes Application in Android Studio.
Algorithm :
Xml :
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">
<ListView
android:id="@+id/listView" android:layout_width="409dp"
android:layout_height="601dp" android:layout_marginTop="80dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent"
<TextView
android:gravity="center_horizontal" android:text="GFG"
android:textColor="@android:color/holo_green_dark" android:textSize="30sp"
app:layout_constraintBottom_toTopOf="@+id/listView"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Xml :
<menu xmlns:android="http://schemas.android.com/apk/res/android">
</menu>
Xml :
android:id="@+id/edit Text"
android:layout_width= "0dp"
android:layout_height
="0dp"
android:ems="10"
android:gravity="top|le
ft"
android:inputType="te xtMultiLine"
app:layout_constraint
Bottom_toBottomOf="
parent"
app:layout_constraint End_toEndOf="parent
"
app:layout_constraint Start_toStartOf="pare
nt"
app:layout_constraint
Top_toTopOf="parent
" /> </androidx.constraintl ayout.widget.Constrai ntLayout>
JAVA:
android.content.Intent; import
android.content.SharedPreferences; import
android.widget.EditText; import
androidx.appcompat.app.AppCompatActivity;
import java.util.HashSet;
int noteId;
@Override
super.onCreate(savedInstanceState); setContentView(R.layout.activity_note_editor);
intent.getIntExtra("noteId", -1);
if (noteId != -1) {
editText.setText(MainActivity.notes.get(noteId));
} else {
MainActivity.arrayAdapter.notifyDataSetChanged();
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
@Override
MainActivity.notes.set(noteId, String.valueOf(charSequence));
MainActivity.arrayAdapter.notifyDataSetChanged();
SharedPreferences sharedPreferences =
getApplicationContext().getSharedPreferences("com.example.notes", Context.MODE_PRIVATE);
sharedPreferences.edit().putStringSet("notes", set).apply();
@Override
});
JAVA:
android.content.DialogInterface; import
android.content.Intent; import
android.content.SharedPreferences; import
android.widget.ArrayAdapter; import
android.widget.ListView; import
androidx.annotation.NonNull; import
androidx.appcompat.app.AlertDialog; import
androidx.appcompat.app.AppCompatActivity;
java.util.HashSet;
ArrayAdapter arrayAdapter;
@Override
return super.onCreateOptionsMenu(menu);
@Override
super.onOptionsItemSelected(item);
if (item.getItemId() == R.id.add_note) {
return false;
@Override
setContentView(R.layout.activity_main);
SharedPreferences sharedPreferences =
getApplicationContext().getSharedPreferences("com.example.notes", Context.MODE_PRIVATE);
HashSet<String> set = (HashSet<String>) sharedPreferences.getStringSet("notes", null);
if (set == null) {
notes.add("Example note");
} else {
listView.setOnItemClickListener(new
AdapterView.OnItemClickListener() {
@Override
intent.putExtra("noteId", i);
startActivity(intent);
});
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
AlertDialog.Builder(MainActivity.this)
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton("Yes", new
DialogInterface.OnClickListener() {
notes.remove(itemToDelete);
arrayAdapter.notifyDataSetChanged();
SharedPreferences
sharedPreferences = getApplicationContext().getSharedPreferences("com.example.notes",
Context.MODE_PRIVATE);
sharedPreferences.edit().putStringSet("notes",
set).apply();
}).setNegativeButton("No", null).show();
return true;
});
}
OUTPUT:
RESULT:
Thus the program to implement database connection has been implemented successfully.