0% found this document useful (0 votes)
11 views

Auto Complete Text View

The document contains code for an Android activity with an AutoCompleteTextView. It includes the XML layout, strings resource, and Java code to populate the AutoCompleteTextView with a string array and set a threshold of 3 characters.

Uploaded by

aherrani757
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Auto Complete Text View

The document contains code for an Android activity with an AutoCompleteTextView. It includes the XML layout, strings resource, and Java code to populate the AutoCompleteTextView with a string array and set a threshold of 3 characters.

Uploaded by

aherrani757
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

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"
tools:context=".MainActivity" >

<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name Of Student" />

<AutoCompleteTextView
android:id="@+id/autoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="AutoCompleteTextView" />
</LinearLayout>

strings.xml

<resources>
<string name="app_name">Autocompletetextview</string>
<string-array name="studlist">
<item>Vaishani</item>
<item>komal</item>
<item>varsha</item>
<item>kiran</item>
<item>pooja</item>
<item>priya</item>
</string-array>
</resources>

MainActivity.java
package com.example.autocompletetextview;

import androidx.appcompat.app.AppCompatActivity;

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

public class MainActivity extends AppCompatActivity {


String[] p;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
p=getResources().getStringArray(R.array.studlist);
AutoCompleteTextView s1=findViewById(R.id.autoCompleteTextView);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item,p);
s1.setThreshold(3);
s1.setAdapter(adapter);
}
}

You might also like