0% found this document useful (0 votes)
7 views3 pages

Practical No. 08

The document provides code for creating an Android application that displays a search engine-like interface using AutoCompleteTextView. It includes XML layout for the main activity and Java code for the MainActivity class, which initializes the AutoCompleteTextView with a list of cities and subjects. The application allows users to select from a predefined list as they type in the text field.

Uploaded by

ganeshkumbhar638
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)
7 views3 pages

Practical No. 08

The document provides code for creating an Android application that displays a search engine-like interface using AutoCompleteTextView. It includes XML layout for the main activity and Java code for the MainActivity class, which initializes the AutoCompleteTextView with a list of cities and subjects. The application allows users to select from a predefined list as they type in the text field.

Uploaded by

ganeshkumbhar638
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/ 3

Q. Write a program to create a first display import android.os.

Bundle;
screen of any search engine using Auto import android.widget.ArrayAdapter;
Complete Text View. import android.widget.AutoCompleteTextView;
Activity_main.xml public class MainActivity extends
AppCompatActivity {
<?xml version="1.0" encoding="utf-8"?> @Override
<LinearLayout protected void onCreate(Bundle
xmlns:android="http://schemas.android.com/apk/ savedInstanceState) {
res/android" String

xmlns:app="http://schemas.android.com/apk/res- str[]={"Mumbai","pune","Sangali","Kolhapur","
auto" Satara","Karad","solapur","Sangali","Dhule"
};
xmlns:tools="http://schemas.android.com/tools" super.onCreate(savedInstanceState);
android:layout_width="match_parent" setContentView(R.layout.activity_main);
android:layout_height="match_parent" AutoCompleteTextView
android:orientation="vertical" autotext=(AutoCompleteTextView)findViewByI
android:gravity="center" d(R.id.ac1);
tools:context=".MainActivity"> ArrayAdapter adapter=new
ArrayAdapter(this,
<TextView
android:id="@+id/textView" androidx.appcompat.R.layout.support_simple_sp
android:layout_width="match_parent" inner_dropdown_item,str);
android:layout_height="wrap_content" autotext.setThreshold(1);
android:textSize="20dp" autotext.setAdapter(adapter);
android:text="Select City : " }
android:paddingHorizontal="80dp" }
android:layout_marginBottom="30dp"/>

<AutoCompleteTextView
android:id="@+id/ac1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="80dp"
android:text=" " />
</LinearLayout>

MainActivity.java

package com.example.practicalno8_1;

import
androidx.appcompat.app.AppCompatActivity;
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20dp"
android:text="Select Subject : "
android:paddingHorizontal="80dp"
android:layout_marginBottom="30dp"/>

<AutoCompleteTextView
android:id="@+id/ac1"
android:layout_width="match_parent"
Q. Write a program to display all the subjects
android:layout_height="wrap_content"
of sixth semester using Auto Complete
Text View. android:layout_marginHorizontal="80dp"
android:text=" " />
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?> </LinearLayout>

<LinearLayout MainActivity.java
xmlns:android="http://schemas.android.com/apk/
res/android" package com.example.practicalno8_1;

xmlns:app="http://schemas.android.com/apk/res- import
auto" androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class MainActivity extends
AppCompatActivity {
@Override
protected void onCreate(Bundle
savedInstanceState) {
String

str[]={"English","Maths","CHY","PHY","EGE",
"Workshop","EEC","BCC","PCI","AMI","CPH"
,"BEC","CGR","CPP","DSU","DBM","DTE","J
PR","DCC","GAD","SEN","MIC","STE","AJP",
"EST","CSS","OSY","NIS","MAD","PWP","ET
I","MAN","EDE"};
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AutoCompleteTextView
autotext=(AutoCompleteTextView)findViewByI
d(R.id.ac1);
ArrayAdapter adapter=new
ArrayAdapter(this,

androidx.appcompat.R.layout.support_simple_sp
inner_dropdown_item,str);
autotext.setThreshold(1);
autotext.setAdapter(adapter);
}
}

You might also like