protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize AutoCompleteTextView and
Button
autoCompleteTextView =
<?xml version="1.0" encoding="utf-8"?
findViewById(R.id.searchAutoCompleteTextView);
>
searchButton =
<RelativeLayout
findViewById(R.id.searchButton);
xmlns:android="http://schemas.android.com/apk/re
s/android"
// Sample list of search terms (can be from a
android:layout_width="match_parent"
database, API, etc.)
android:layout_height="match_parent"
String[] searchSuggestions = new String[]{
android:padding="16dp">
"Android", "Apple", "Amazon",
"Artificial Intelligence", "Android Studio",
<AutoCompleteTextView
"Application Development", "AI
research", "Autonomous Vehicles", "Artificial
android:id="@+id/searchAutoCompleteTextView"
Intelligence Jobs"
android:layout_width="match_parent"
};
android:layout_height="wrap_content"
android:hint="Search here"
// Create an ArrayAdapter using the search
android:padding="10dp"
suggestions
android:textSize="16sp"
ArrayAdapter<String> adapter = new
android:dropDownHeight="200dp"/>
ArrayAdapter<>(this,
android.R.layout.simple_dropdown_item_1line,
<Button
searchSuggestions);
android:id="@+id/searchButton"
android:layout_width="wrap_content"
// Set the adapter to AutoCompleteTextView
android:layout_height="wrap_content"
autoCompleteTextView.setAdapter(adapter);
android:text="Search"
// Set up the search button click listener
android:layout_below="@id/searchAutoCompleteT
searchButton.setOnClickListener(new
extView"
View.OnClickListener() {
android:layout_marginTop="16dp"
@Override
android:layout_centerHorizontal="true" />
public void onClick(View v) {
// Get the text entered in the
</RelativeLayout>
AutoCompleteTextView
package com.example.myapplication10;
String query =
autoCompleteTextView.getText().toString();
import android.os.Bundle;
// Show a toast with the query (you can
import android.view.View;
replace this with actual search functionality)
import android.widget.ArrayAdapter;
Toast.makeText(MainActivity.this,
import android.widget.AutoCompleteTextView;
"Searching for: " + query,
import android.widget.Button;
Toast.LENGTH_SHORT).show();
import android.widget.Toast;
} });
}
import
}
androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends
AppCompatActivity {
private AutoCompleteTextView
autoCompleteTextView;
private Button searchButton;
@Override