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

Practical No 8

The document outlines the implementation of an Auto Complete Text View in an Android application. It includes the XML layout for the main activity and the Java code for the MainActivity class, which sets up an AutoCompleteTextView with a predefined list of colors. The AutoCompleteTextView suggests colors as the user types, enhancing user experience in selecting color options.

Uploaded by

Kolekar Yashraj
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)
6 views3 pages

Practical No 8

The document outlines the implementation of an Auto Complete Text View in an Android application. It includes the XML layout for the main activity and the Java code for the MainActivity class, which sets up an AutoCompleteTextView with a predefined list of colors. The AutoCompleteTextView suggests colors as the user types, enhancing user experience in selecting color options.

Uploaded by

Kolekar Yashraj
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

Practical No.

8 : Develop a program to Implement Auto


Complete Text View
▪ Activity_main.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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/color"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="150dp"
android:text="Enter Color"
android:textSize="30dp"
android:layout_marginLeft="20dp"
android:textStyle="bold"
android:textColor="@color/black"
/>

<AutoCompleteTextView
android:id="@+id/autoCompleteTextView"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="170dp"
android:layout_marginTop="150dp"
android:hint="Enter your color"
android:textStyle="bold"
android:textSize="20dp"
/>
</RelativeLayout>
▪ mainActivity.java

package com.example.autocompleteexample;

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

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {

AutoCompleteTextView autoCompleteTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
autoCompleteTextView = findViewById(R.id.autoCompleteTextView);
String[] color = {
"Red",
"Green",
"Voilet",
"Yellow",
"Blue",
"Black",
"White",

};
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.select_dialog_item,color);

autoCompleteTextView.setThreshold(1);
autoCompleteTextView.setAdapter(adapter);
}
}

You might also like