0% found this document useful (0 votes)
98 views2 pages

Practical No 08

This document describes how to create an auto-complete text view in Android. It includes the XML layout code to design the user interface with a text view and auto-complete text view. It also includes the Java code in the MainActivity class to populate the auto-complete text view with string options, set the threshold and adapter, and set the text color. When run, it will display an auto-complete text view that suggests options as the user types.

Uploaded by

Vaibhav Bhagwat
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)
98 views2 pages

Practical No 08

This document describes how to create an auto-complete text view in Android. It includes the XML layout code to design the user interface with a text view and auto-complete text view. It also includes the Java code in the MainActivity class to populate the auto-complete text view with string options, set the threshold and adapter, and set the text color. When run, it will display an auto-complete text view that suggests options as the user types.

Uploaded by

Vaibhav Bhagwat
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/ 2

Practical No: 8

 Develop a program to implement Auto complete Text view.

 activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout 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"
android:orientation="vertical"
android:background="#3EB489"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="31dp"
android:text="What is your favourite programming language?"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.032"
/>

<AutoCompleteTextView
android:id="@+id/autoCompleteTextView"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="92dp"
android:layout_marginTop="144dp"
android:hint="Search here ......"
android:text=""
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</LinearLayout>

 MainActivity.java
package com.example.pr8;
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 {
String[] language ={"C","C++","Java",".NET","ASP.NET","PHP"};
@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,language);
AutoCompleteTextView actv =
(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView);
actv.setThreshold(1);
actv.setAdapter(adapter);
actv.setTextColor( Color.RED);
}
}

 Output:

You might also like