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

Ex 8

The document describes an Android application that implements an autocomplete text view. It includes the XML layout file and Java code to populate the autocomplete text view with a string array of search suggestions.

Uploaded by

suyashkurunkar
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)
26 views3 pages

Ex 8

The document describes an Android application that implements an autocomplete text view. It includes the XML layout file and Java code to populate the autocomplete text view with a string array of search suggestions.

Uploaded by

suyashkurunkar
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

Ex8_1

Xml file:-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<AutoCompleteTextView
android:id="@+id/actv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:hint="Search"
android:padding="10dp"
android:textColor="#000"
android:textSize="16sp" />

</LinearLayout>

Java file:-

package com.example.ex8_1;

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

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

String[] searchSuggestions = {"Google", "Bing", "Yahoo",


"DuckDuckGo", "Baidu"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AutoCompleteTextView actv = findViewById(R.id.actv);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_dropdown_item_1line, searchSuggestions);
actv.setAdapter(adapter);
}
}

output:-
Ex8_2

Xml file:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<AutoCompleteTextView
android:id="@+id/actv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Select Subject"
android:textColor="#000" />

</RelativeLayout>
Java file:-
package com.example.ex8_2;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

String[] s = {"MGT","PWP","WBP","MAD","ETI"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

AutoCompleteTextView actv1 = findViewById(R.id.actv);


ArrayAdapter<String> adapter = new
ArrayAdapter<>(this,android.R.layout.simple_dropdown_item_1line, s);
actv1.setAdapter(adapter);
}
}

output:-

You might also like