0% found this document useful (0 votes)
24 views4 pages

PR 8

The document contains two practical programming tasks focused on creating user interfaces using AutoCompleteTextView in Android. The first task involves building a search engine display screen with a list of cities, while the second task displays subjects for the sixth semester. Each task includes XML layout code and corresponding Java code for implementation.

Uploaded by

Samiksha Bhosale
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)
24 views4 pages

PR 8

The document contains two practical programming tasks focused on creating user interfaces using AutoCompleteTextView in Android. The first task involves building a search engine display screen with a list of cities, while the second task displays subjects for the sixth semester. Each task includes XML layout code and corresponding Java code for implementation.

Uploaded by

Samiksha Bhosale
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
You are on page 1/ 4

Practical 8

Q1. Write a program to create a first display screen of any search engine using Auto Complete Text View

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="wrap_content"
android:layout_height="wrap_content"
android:text="Google"
android:textColor="#FD0303"
android:textSize="40dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.535"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.082" />
<AutoCompleteTextView
android:id="@+id/ac1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="182dp"
android:layout_marginBottom="504dp"
android:dropDownWidth="match_parent"
android:dropDownHeight="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

String.xml code:

<resources>
<string name="app_name">Search Engine</string>
<string-array name="cities">
<item>"Kolhapur"</item>
<item>"Pune"</item>
<item>"Mumbai"</item>
<item>"Nashik"</item>
<item>"Nagpur"</item>
<item>"Kolkata"</item>
<item>"Manipur"</item>
<item>"Patna"</item>
</string-array>
</resources>
Practical 8
JAVA code:

package com.example.searchengine;
import androidx.appcompat.app.AppCompatActivity;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Resources res=getResources();
String[] city=res.getStringArray(R.array.cities);
ArrayAdapter<String> adapter=new
ArrayAdapter<String>(this,android.R.layout.select_dialog_item,city);
AutoCompleteTextView actv=(AutoCompleteTextView)findViewById(R.id.ac1);
actv.setThreshold(1);
actv.setAdapter(adapter);
}
}

Output:
Practical 8
Q2. Write a program to display all the subjects of sixth semester using Auto Complete Text View

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">
<AutoCompleteTextView
android:id="@+id/ac1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="191dp"
android:layout_marginBottom="495dp"
android:dropDownWidth="match_parent"
android:dropDownHeight="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/t1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="133dp"
android:layout_marginBottom="579dp"
android:text="Subjects for 6th semester"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

JAVA code:

package com.example.autocomplete;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class MainActivity extends AppCompatActivity {
String[] subjects={"PWP","MAD","ETI","EDE","MGT","NIS","CPE"};
@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,subjects);
AutoCompleteTextView actv = (AutoCompleteTextView)findViewById(R.id.ac1);
actv.setThreshold(1);
actv.setAdapter(adapter);
}}
Practical 8
Output:

You might also like