Question 09: Write a program to create a first display screen of any search engine using Auto Complete Text View.
Download hole Program / Project code, by clicking following link:
What does android:completionHint attribute in Auto Complete Text view does?
The android:completionHint attribute in AutoCompleteTextView is used to specify a hint text that appears below the AutoCompleteTextView when it is used to display a list of suggestions. This attribute is optional and is used to provide additional context or information to the user about the list of suggestions being displayed.
When the user types in an AutoCompleteTextView, a list of suggestions is displayed based on the text entered so far. The android:completionHint attribute can be used to display a hint text below the list of suggestions that provides additional information about what the user can expect to see in the list. For example, if the AutoCompleteTextView is being used to search for cities, the android:completionHint attribute can be used to display a hint text such as "Search for a city name" below the list of suggestions.
The android:completionHint attribute takes a string value, which is used as the hint text to display below the list of suggestions. By default, the hint text is displayed in a gray color and is styled to look like a hint text. However, the appearance of the hint text can be customized using the android:completionHintView attribute, which allows a custom view to be used instead of the default hint text view.
Programming Code:
Following code write in: MainActivity.java
package com.go2collage.practical_09;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class MainActivity extends AppCompatActivity {
private AutoCompleteTextView autoCompleteTextView;
private String search_engine [] = {"Google", "Yahoo", "Bing", "Wiki"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
autoCompleteTextView = findViewById(R.id.autoCompleteTxt);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, search_engine);
autoCompleteTextView.setThreshold(1);
autoCompleteTextView.setAdapter(adapter);
}
}
Following code write in: 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"
tools:context=".MainActivity"
android:orientation="vertical"
android:layout_margin="20dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="go2collage"
android:textSize="24sp"
android:textStyle="bold"
android:textAlignment="center"
android:layout_marginTop="20dp"
android:layout_marginBottom="50dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Search Engine"
android:textSize="20sp"
android:textAlignment="center"
android:textStyle="bold"
android:textColor="@color/black"
tools:ignore="HardcodedText" />
<AutoCompleteTextView
android:id="@+id/autoCompleteTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:hint="Search..."
android:minHeight="48dp"
android:textColor="@color/black"
android:textSize="18sp"
tools:ignore="HardcodedText" />
</LinearLayout>
Output:
0 Comments