0% found this document useful (0 votes)
7 views2 pages

Practical 8.2

The document provides a code example for an Android application that displays subjects for the sixth semester using an AutoCompleteTextView. It includes the XML layout for the user interface and the Java code for the main activity, which sets up the AutoCompleteTextView with a list of subject suggestions. The application allows users to search for subjects by typing in the text field, with suggestions appearing as they type.

Uploaded by

Kolekar Yashraj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Practical 8.2

The document provides a code example for an Android application that displays subjects for the sixth semester using an AutoCompleteTextView. It includes the XML layout for the user interface and the Java code for the main activity, which sets up the AutoCompleteTextView with a list of subject suggestions. The application allows users to search for subjects by typing in the text field, with suggestions appearing as they type.

Uploaded by

Kolekar Yashraj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

2.

Write a program to display all the subjects of sixth


semester using Auto Complete Text View
▪ Activity_main.xml

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


<androidx.constraintlayout.widget.ConstraintLayout
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">
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:hint="Search here"
android:textColor="@android:color/black"
android:padding="12dp"
android:background="@android:color/white"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

▪ MainActivity.java
package com.example.prac82;
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);
AutoCompleteTextView searchView = findViewById(R.id.autoCompleteTextView);
String[] suggestions = {
"WBP", "PWP", "ETI", "EDE", "MGT",
"CPP"
};
ArrayAdapter<String> adapter = new ArrayAdapter<>(
this, android.R.layout.simple_dropdown_item_1line, suggestions
);
searchView.setAdapter(adapter);
searchView.setThreshold(1);
}
}

You might also like