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

Name:Panchal Deep Kamlesh SEAT NO.: 2009561 Class: Sycs 20-21 Subject: Android Journal

The document describes steps to install Android Studio and create a "Hello World" Android app: 1. Download and install Android Studio by running the .exe file and following prompts. 2. Create a new Android project and empty activity called "MainActivity". 3. Add XML layout code and Java code to display "Hello World!" as the app output. 4. Run the app in the Android emulator to see the output.

Uploaded by

Deep K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

Name:Panchal Deep Kamlesh SEAT NO.: 2009561 Class: Sycs 20-21 Subject: Android Journal

The document describes steps to install Android Studio and create a "Hello World" Android app: 1. Download and install Android Studio by running the .exe file and following prompts. 2. Create a new Android project and empty activity called "MainActivity". 3. Add XML layout code and Java code to display "Hello World!" as the app output. 4. Run the app in the Android emulator to see the output.

Uploaded by

Deep K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 39

NAME :PANCHAL DEEP

KAMLESH
SEAT NO. : 2009561
CLASS : SYCS 20-21
SUBJECT : ANDROID JOURNAL
Practical 1:

a) Installation of Android Studio & Hello World Program


Download AndroidStudio.exe file
Run the .exe File
The installer will respond by presenting the Android Studio
Setup dialog box shown below

Clicking on the Next it will take you to the following


panel, which provides the option to install an Android
Virtual Device(AVD)

Keep the default settings, and click on the Next, It will take you to
the Configuration Settings Panel, where It will ask you the
location to install Android Studio.

Keep the default installation location and click Next, and


will greet with the Choose Start Menu Folder panel.
Keep the default setting and click Install. The Following
Installing panel will appear:

When the installation get finish, the Installation Complete panel


will get appear:

After clicking Next, the installer will present the Completing


Android Studio Setup panel.
To complete the installation, keep the Start Android Studio box
checked & click on Finish.

Running Android Studio


The First time Android Studio runs, it presents a Complete
Installation dialog box that offers the option of importing
setting from a previous installation.
Chose not to import settings(the default selection) and click
on OK, & it will reward with the following splash screen⁰

While the setup is getting ready, you will observe


the following Finding Available SDK
Components message box.

At this point the Android Studio will present the following


Android Studio Setup Wizard
dialog box:

Click on Next, and the wizard will give you the option to
select the installation type. Keep the default Standard
setting.

It will give you the opportunity to choose a user interface theme

Keep the default IntelliJ setting and click Next. Android


Studio will provide the opportunity to verify settings.
Click on finish and Android Studio will began the process of
downloading SDK components.

It will take several minutes for this part of this part of the
setup to finish. Clicking Show Details, it will show the
various files being downloaded and unzipped.
After the Installation, get Finish. The Welcome to Android
Studio dialog box will get appear.

Click on Start a new Android Studio Project


Android Studio will respond with the Create New Project dialog

box shown below.

Android Studio lets you select form factors, or categories of


target devices, for every app you create. I kept the default
setting.
Click Next, and you will be given the opportunity to
choose a template for your app's main activity. For now
we'll stick with Empty Activity. Select this template (if
necessary) and click Next.

Next you'll customize the activity:


Enter the activity name and main as the layout name, and click
Next to complete this step.

The first time you use Android Studio, you'll discover


that it has to download some files related to its
constraint layout, which is used to build responsive user

interfaces:
Android Studio enables Finish after downloading the
constraint layout files. Click this button and Android Studio
takes you to the main window.

The main window is divided into a menu bar and several other

areas

b) Running the First App in Android Studio Hello World!

activity_main.xml code:
<?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:layout_width="235dp"
android:layout_height="53dp"
android:layout_marginStart="88dp"
android:layout_marginLeft="88dp"
android:layout_marginTop="227dp"
android:layout_marginEnd="88dp"
android:layout_marginRight="88dp"
android:layout_marginBottom="451dp"
android:textSize="30dp"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java Code:
package com.example.prac_1;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {


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

Output & Design:

Practical 2: a) Program to Design a login page


XML code:

<?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/Tv1"
android:layout_width="140dp"
android:layout_height="52dp"
android:layout_marginStart="50dp"
android:layout_marginLeft="50dp"
android:layout_marginTop="104dp"
android:text="Enter username"
android:textSize="18sp"
app:layout_constraintBottom_toTopOf="@+id/Tv2"
app:layout_constraintEnd_toStartOf="@+id/Us1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/Tv2"
android:layout_width="140dp"
android:layout_height="52dp"
android:layout_marginStart="50dp"
android:layout_marginLeft="50dp"
android:layout_marginBottom="523dp"
android:text="Enter password"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/Pswd"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/Tv1" />

<EditText
android:id="@+id/Us1"
android:layout_width="190dp"
android:layout_height="52dp"
android:layout_marginTop="104dp"
android:layout_marginEnd="6dp"
android:layout_marginRight="6dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBottom_toTopOf="@+id/Pswd"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/Tv1"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/Pswd"
android:layout_width="190dp"
android:layout_height="52dp"
android:layout_marginEnd="6dp"
android:layout_marginRight="6dp"
android:layout_marginBottom="523dp"
android:ems="10"
android:inputType="textPassword"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/Tv2"
app:layout_constraintTop_toBottomOf="@+id/Us1" />

<Button
android:id="@+id/b1"
android:layout_width="176dp"
android:layout_height="39dp"
android:layout_marginStart="56dp"
android:layout_marginLeft="56dp"
android:layout_marginTop="70dp"
android:layout_marginEnd="179dp"
android:layout_marginRight="179dp"
android:layout_marginBottom="441dp"
android:text="Login"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/Tv2" />

<TextView
android:id="@+id/Tv3"
android:layout_width="212dp"
android:layout_height="40dp"
android:layout_marginStart="110dp"
android:layout_marginLeft="110dp"
android:layout_marginTop="50dp"
android:layout_marginEnd="89dp"
android:layout_marginRight="89dp"
android:layout_marginBottom="381dp"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/b1" />
</androidx.constraintlayout.widget.ConstraintLayout>

Java Code:
package com.example.prac_2a;

import androidx.appcompat.app.AppCompatActivity;

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

public class MainActivity extends AppCompatActivity {


private EditText userName;
private EditText Password;
private Button Login;
private TextView Label;

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

userName = (EditText) findViewById(R.id.Us1);


Password = (EditText) findViewById(R.id.Pswd);
Login = (Button) findViewById(R.id.b1);
Label = (TextView) findViewById(R.id.Tv3);

Login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (userName.getText().toString().equals("admin") &&
Password.getText().toString().equals("admin")) {
Label.setText("login successful");
} else {
Label.setText("Invalid credentials");
}
}
});
}
}

Output & Design :


b) Program to Design a login page and change the layout(colours, font, etc).

XML Code :
<?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" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#818080"
android:orientation="vertical"
tools:layout_editor_absoluteX="150dp"
tools:layout_editor_absoluteY="221dp">

<TextView
android:id="@+id/Tv1"
android:layout_width="174dp"
android:layout_height="46dp"
android:background="#020202"
android:text="Enter username"
android:textColor="#0337D1"
android:textSize="20sp" />

<EditText
android:id="@+id/Us1"
android:layout_width="match_parent"
android:layout_height="49dp"
android:background="#FFFFFF"
android:ems="10"
android:inputType="textPersonName"
android:textColor="#C80606" />

<TextView
android:id="@+id/Tv2"
android:layout_width="176dp"
android:layout_height="47dp"
android:background="#000000"
android:text="Enter password"
android:textColor="#0337D1"
android:textSize="20sp" />

<EditText
android:id="@+id/Pswd"
android:layout_width="match_parent"
android:layout_height="52dp"
android:background="#FFFFFF"
android:ems="10"
android:inputType="textPassword"
android:textColor="#C80606" />

<Button
android:id="@+id/b1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login" />

<TextView
android:id="@+id/Tv3"
android:layout_width="match_parent"
android:layout_height="36dp"
android:textColor="#3ECA0D" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

Java code:
package com.example.prac_2b;

import androidx.appcompat.app.AppCompatActivity;

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

public class MainActivity extends AppCompatActivity {


private EditText userName;
private EditText Password;
private Button Login;
private TextView Label;

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

userName = (EditText) findViewById(R.id.Us1);


Password = (EditText) findViewById(R.id.Pswd);
Login = (Button) findViewById(R.id.b1);
Label = (TextView) findViewById(R.id.Tv3);

Login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (userName.getText().toString().equals("admin") &&
Password.getText().toString().equals("admin")) {
Label.setText("Login successful");
} else {
Label.setText("Invalid credentials");
}
}
});
}
}

Output and Design:


Practical 3: Program to create check boxes and show its functioning.

XML Code:
<?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" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#46CAAF"
android:orientation="vertical"
tools:layout_editor_absoluteX="99dp"
tools:layout_editor_absoluteY="260dp">

<TextView
android:id="@+id/Tv"
android:layout_width="match_parent"
android:layout_height="102dp"
android:background="#FFFFFF"
android:text="enter your name and select the Countries you want to
visit"
android:textSize="30sp" />

<EditText
android:id="@+id/Us1"
android:layout_width="match_parent"
android:layout_height="60dp"
android:autofillHints=""
android:background="#77DD01"
android:textColor="#BC0303" />

<CheckBox
android:id="@+id/cb1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="INDIA"
android:textSize="18sp"
app:buttonTint="#BD2323" />

<CheckBox
android:id="@+id/cb2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ENGLAND"
android:textSize="18sp"
app:buttonTint="#BD2323" />

<CheckBox
android:id="@+id/cb3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="USA"
android:textSize="18sp"
app:buttonTint="#BD2323" />

<Button
android:id="@+id/b1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Submit" />

<TextView
android:id="@+id/Tv2"
android:layout_width="match_parent"
android:layout_height="223dp"
android:background="#FFFFFF"
android:text=""
android:textSize="20sp" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

Java Code:
package com.example.prac_3;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {


private EditText Name;
private Button submit;
private TextView Label;
CheckBox c1,c2,c3;

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

Name = (EditText) findViewById(R.id.Us1);


submit= (Button) findViewById(R.id.b1);
Label = (TextView) findViewById(R.id.Tv2);
c1 = (CheckBox)findViewById(R.id.cb1);
c2 = (CheckBox)findViewById(R.id.cb2);
c3 = (CheckBox)findViewById(R.id.cb3);

submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Name.getText().toString();
System.out.println(Name+" wishes to visit the countires:");
if(c1.isChecked())
{ System.out.println("INDIA"); }
if(c2.isChecked())
{ System.out.println("ENGLAND"); }
if(c3.isChecked())
{ System.out.println("USA"); }

}
});
}
}

Output & Design:


Practical 4: Program to create radio buttons and display its functioning.

XML Code:
<?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">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#454545"
android:orientation="vertical"
tools:layout_editor_absoluteX="10dp"
tools:layout_editor_absoluteY="48dp">

<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#454545"
android:text="Enter your name"
android:textSize="20sp" />

<EditText
android:id="@+id/Et1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:ems="10"
android:inputType="textPersonName"
android:visibility="visible" />

<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#454545"
android:text="Enter your DOB"
android:textSize="20sp" />

<EditText
android:id="@+id/editTextTextPersonName2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:ems="10"
android:inputType="textPersonName" />

<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#454545"
android:text="Gender"
android:textSize="20sp" />

<RadioGroup
android:id="@+id/radio"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<RadioButton
android:id="@+id/radioButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:text="Male"
android:textColor="#045597"
android:textSize="20sp"
app:buttonTint="#BC0101" />

<RadioButton
android:id="@+id/radioButton2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:text="Female"
android:textColor="#045597"
android:textSize="20sp"
app:buttonTint="#BC0101" />
</RadioGroup>

<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Submit" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

Java Code:
package com.example.prac_4;

import androidx.appcompat.app.AppCompatActivity;

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

public class MainActivity extends AppCompatActivity implements


View.OnClickListener {
private RadioButton radioSexButton;
private RadioGroup radioSexGroup;
private Button disp;
private EditText Name;
int SelectedId;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
radioSexGroup = findViewById(R.id.radio);
disp = findViewById(R.id.button);
disp.setOnClickListener(this);
Name = findViewById(R.id.Et1);
}
public void onClick(View v){
SelectedId= radioSexGroup.getCheckedRadioButtonId();
radioSexButton= findViewById(SelectedId);

Toast.makeText(getApplicationContext(),radioSexButton.getText(),Toast.LENGTH_LONG)
.show();
}
}

Design and Output:


Practical 5: Program to create and display the functioning of togglebutton.

XML Code:
<?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">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#707AB1"
tools:layout_editor_absoluteX="63dp"
tools:layout_editor_absoluteY="186dp">

<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="100dp"
android:layout_marginTop="40dp"
android:text="ToggleButton" />

<ToggleButton
android:id="@+id/toggleButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="100dp"
android:layout_marginTop="100dp"
android:text="ToggleButton" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="250dp"
android:layout_marginTop="175dp"
android:text="Button" />
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

Java Code:
package com.example.prac_5;

import androidx.appcompat.app.AppCompatActivity;

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

public class MainActivity extends AppCompatActivity implements


View.OnClickListener{
ToggleButton t1,t2;
Button b1;
StringBuffer result1, result2;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
t1=findViewById(R.id.toggleButton);
t2=findViewById(R.id.toggleButton2);
b1=findViewById(R.id.button);
b1.setOnClickListener(this);
}
public void onClick(View view) {
result1 = new StringBuffer();
result1.append(t1.getText());

result2 = new StringBuffer();


result2.append(t2.getText());

Toast.makeText(getApplicationContext(), "Toggle button1=" +


result1.toString() + "Toggle button2=" + result2.toString(),
Toast.LENGTH_SHORT).show();
}
}

Design and Output:


Practical 6: Program to create and display the functioning of Progressbar.

XML Code:
<?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:background="#CC5C5C"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="100dp"
android:layout_marginTop="50dp"
android:background="#FFFFFF"
android:text="@string/progress_bar"
android:textSize="18sp" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="100dp"
android:layout_marginTop="100dp"
android:onClick="download"
android:text="@string/download"
android:textSize="18sp" />

</RelativeLayout>

Java Code:
package com.example.prac_6;

import androidx.appcompat.app.AppCompatActivity;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {


Button b1;

private ProgressDialog progress;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=findViewById(R.id.button);
}
public void download(View view){
progress =new ProgressDialog(this);
progress.setMessage("Download Music");
progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progress.setIndeterminate(false);
progress.setProgress(0);
progress.show();

final int progress1=100;


final Thread t = new Thread(){
public void run(){
int jump=0;

while (jump<progress1){
try{
sleep(200);
jump=jump+5;
progress.setProgress(jump);
}
catch (InterruptedException e){
e.printStackTrace();
}
}
}
};
t.start();
}
}

Output & Design:


Practical 7:

a) Program to create a listview and display its functionality.

XML Code:
<?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">

<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:listSelector="@color/design_default_color_error" />
</RelativeLayout>

Java Code:
package com.example.prac_7a;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView=(ListView)findViewById(R.id.listview);

ArrayList<String> arrayList= new ArrayList<>();

arrayList.add("Dog");
arrayList.add("Cat");
arrayList.add("Hamster");
arrayList.add("Fish");
arrayList.add("Puma");
arrayList.add("Sheep");
arrayList.add("Goat");
arrayList.add("Cow");
arrayList.add("Buffalo");
arrayList.add("Tiger");
ArrayAdapter arrayAdapter= new
ArrayAdapter(this,android.R.layout.simple_list_item_1,arrayList);
listView.setAdapter(arrayAdapter);

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i,
long l){
Toast.makeText(MainActivity.this,"clicked item:"+i+"
"+arrayList.get(i).toString(),Toast.LENGTH_SHORT).show();
}
});

}
}

Output & Design:


b) Program to create a listview with elements as Operating systems and display its
functionality.

XML Code:
<?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">

<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:listSelector="@color/teal_200" />
</RelativeLayout>

Java Code:
package com.example.prac_7b;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView=(ListView)findViewById(R.id.listview);

ArrayList<String> arrayList= new ArrayList<>();

arrayList.add("Windows");
arrayList.add("Linux");
arrayList.add("MacOS");
arrayList.add("Ubantu");
arrayList.add("MSDOS");
arrayList.add("Unix");
arrayList.add("iOS");
arrayList.add("Android");

ArrayAdapter arrayAdapter= new


ArrayAdapter(this,android.R.layout.simple_list_item_1,arrayList);
listView.setAdapter(arrayAdapter);

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i,
long l){
Toast.makeText(MainActivity.this,"clicked item:"+i+"
"+arrayList.get(i).toString(),Toast.LENGTH_SHORT).show();
}
});
}
}

Output & Design:


Practical 8: Program to create and display the functionality of AutoCompleteTextView.

XML Code:
<?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">

<TextView
android:id="@+id/t1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:text="Which is your favourite programming language"
android:textColor="#FFFFFF"
android:textSize="24sp" />

<AutoCompleteTextView
android:id="@+id/a1"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="92dp"
android:layout_marginTop="144dp"
android:background="#FFFFFF"
android:text=""
android:textColor="#000000" />
</RelativeLayout>
Java Code:
package com.example.prac8;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class MainActivity extends AppCompatActivity {


public String[]t1={"Android","java","OS","Python","Advanced java"};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayAdapter<String> adapter = new ArrayAdapter<String>
(this,android.R.layout.select_dialog_item,t1);
AutoCompleteTextView actv = (AutoCompleteTextView)findViewById(R.id.a1);
actv.setThreshold(1);
actv.setAdapter(adapter);
actv.setTextColor(Color.RED);
}
}

Output and Design:


Practical 9: Program to connect to internet via app.

XML Code:
<?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">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:layout_editor_absoluteX="35dp"
tools:layout_editor_absoluteY="248dp">

<EditText
android:id="@+id/edit"
android:layout_width="match_parent"
android:layout_height="84dp"
android:ems="10"
android:inputType="textPersonName"
android:textSize="18sp" />

<Button
android:id="@+id/button"
android:layout_width="6dp"
android:layout_height="6dp"
android:text="Button" />
<Button
android:id="@+id/b"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Go" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

Java Code:
package com.example.prac_9;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {


public EditText E1;
public String url;
public Intent i;
public Button b;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
E1 = findViewById(R.id.edit);
b =findViewById(R.id.b);
b.setOnClickListener(this::Internet);

}
public void Internet(View view){
url="https://"+E1.getText().toString();
i= new Intent(Intent.ACTION_VIEW,Uri.parse(url));
startActivity(i);
}
}
Output & Design:

You might also like