0% found this document useful (0 votes)
49 views4 pages

MAD Exp 8

The document describes creating an autocomplete text view in Android to display search suggestions or a list of subjects. It includes XML layout code to define the autocomplete text view and Java code to populate it with string arrays and set up an adapter.

Uploaded by

Oaish Qazi
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)
49 views4 pages

MAD Exp 8

The document describes creating an autocomplete text view in Android to display search suggestions or a list of subjects. It includes XML layout code to define the autocomplete text view and Java code to populate it with string arrays and set up an adapter.

Uploaded by

Oaish Qazi
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/ 4

Oaish Qazi 1|Page

Practical No 8:

Q. Write a Program to create a first display screen of any search engine using
AutoCompleteTextView.

CODE:
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:padding="15dp">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100sp"
android:src="@drawable/google"/>
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionThreshold="1"
android:id="@+id/actv"
android:textSize="20sp"
android:layout_marginTop="50sp"
android:drawableLeft="@drawable/search"
android:drawableRight="@drawable/mic"
android:hint="Search Google or enter URL"/>
</LinearLayout>
Oaish Qazi 2|Page

JAVA:
package com.example.myapplication;

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

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[] searchHints = {"How to run android", "How to download SDK", "How to create an android project"};
ArrayAdapter<String> adp = new ArrayAdapter<String>(this, android.R.layout.select_dialog_item, searchHints);
AutoCompleteTextView actv = (AutoCompleteTextView) findViewById(R.id.actv);
actv.setThreshold(1);
actv.setAdapter(adp);
}
}

OUTPUT:

Q. Write a program to display all the Subjects of VI Semester using AutoCompleteTextView.


CODE:
XML:
Oaish Qazi 3|Page

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


<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:padding="15dp"
android:layout_marginTop="180dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Subjects of VI Semester"
android:layout_gravity="center"
android:textSize="30sp"/>
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/actv"
android:textSize="20sp"
android:hint="Search for subjects"/>
</LinearLayout>

JAVA:
package com.example.myapplication;

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

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

String[] searchHints = {"CPE", "EDE", "ETI", "MAD", "MAN", "PWP", "WBP"};


ArrayAdapter<String> adp = new ArrayAdapter<>(this, android.R.layout.select_dialog_item, searchHints);

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


actv.setThreshold(0);
actv.setAdapter(adp);

actv.setOnFocusChangeListener((view, hasFocus) -> {


if (hasFocus)
actv.showDropDown();
});
Oaish Qazi 4|Page

}
}

OUTPUT:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy