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

PR No 8-Mad

The document provides code to implement an autocomplete text view in Android. It includes XML and Java code to create a autocomplete text view that suggests fruits for the first example. For the second example, it displays subjects for the sixth semester using autocomplete text view populated with subject names. The code initializes the autocomplete text view, creates an array adapter with the data, and sets the adapter.

Uploaded by

Sandesh Gaikwad
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)
19 views3 pages

PR No 8-Mad

The document provides code to implement an autocomplete text view in Android. It includes XML and Java code to create a autocomplete text view that suggests fruits for the first example. For the second example, it displays subjects for the sixth semester using autocomplete text view populated with subject names. The code initializes the autocomplete text view, creates an array adapter with the data, and sets the adapter.

Uploaded by

Sandesh Gaikwad
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/ 3

PR NO 8 :

Develop a program to implement AutoComplete Text View..

Q1: Write a program to create a first display screen of any search engine using Auto

Complete Text View.

Ans. XML CODE :


<?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:orientation="vertical"

android:padding="16dp">

<AutoCompleteTextView

android:id="@+id/auto_complete_text_view"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Search..."

android:completionThreshold="1" />

</LinearLayout>

Java code :

import android.os.Bundle;

import android.widget.ArrayAdapter;

import android.widget.AutoCompleteTextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

private String[] suggestions = {"Apple", "Banana", "Orange", "Grapes", "Pineapple", "Watermelon",


"Mango"};

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

// Initialize AutoCompleteTextView

AutoCompleteTextView autoCompleteTextView = findViewById(R.id.auto_complete_text_view);

// Create ArrayAdapter with suggestions

PR NO 8 : Page 1 of 3
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_dropdown_item_1line, suggestions);

// Set the adapter to the AutoCompleteTextView

autoCompleteTextView.setAdapter(adapter);

Q.2 : Write a program to display all the subjects of sixth semester using Auto Complete

Text View.

ANS . XML CODE :

<?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:orientation="vertical"

android:padding="16dp">

<AutoCompleteTextView

android:id="@+id/auto_complete_text_view"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Select subject..."

android:completionThreshold="1" />

</LinearLayout>

JAVA CODE:

import android.os.Bundle;

import android.widget.ArrayAdapter;

import android.widget.AutoCompleteTextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

PR NO 8 : Page 2 of 3
private String[] sixthSemesterSubjects = {"Operating Systems", "Computer Networks", "Database
Management Systems", "Software Engineering", "Web Technologies", "Compiler Design"};

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

// Initialize AutoCompleteTextView

AutoCompleteTextView autoCompleteTextView = findViewById(R.id.auto_complete_text_view);

// Create ArrayAdapter with sixth semester subjects

ArrayAdapter<String> adapter = new ArrayAdapter<>(this,


android.R.layout.simple_dropdown_item_1line, sixthSemesterSubjects);

// Set the adapter to the AutoCompleteTextView

autoCompleteTextView.setAdapter(adapter);

PR NO 8 : Page 3 of 3

You might also like