Ad Code

Responsive Advertisement

Basic Android Program 10

Question 10: Write a program to display all the subjects of sixth semester using Auto Complete Text View.

Download hole Program / Project code, by clicking following link:

How to create AutoCompleteTextView field in XML?

To create an AutoCompleteTextView field in XML, you can use the following steps:
  1. Open the XML file where you want to add the AutoCompleteTextView field.
  2. Add the <AutoCompleteTextView> tag to create the AutoCompleteTextView field.
  3. Set the android:id attribute to a unique ID for the AutoCompleteTextView field.

  4. Set the android:layout_width and android:layout_height attributes to specify the width and height of the field.
  5. Set the android:completionThreshold attribute to specify the minimum number of characters that must be typed before the AutoCompleteTextView starts suggesting completions.
  6. Set the android:completionHint attribute to specify a hint text that appears below the AutoCompleteTextView when it is used to display a list of suggestions (optional).
  7. Set the android:inputType attribute to specify the type of input expected, such as text or phone number.

  8. Set the android:imeOptions attribute to specify additional options for the input method editor (IME), such as the action button to display on the keyboard.

  9. Set the android:textColor attribute to specify the color of the text in the field.
  10. Set the android:textSize attribute to specify the size of the text in the field.

  11. Set the android:hint attribute to specify a hint text that appears in the field when it is empty.
Here's an example XML code to create an AutoCompleteTextView field:

<AutoCompleteTextView
android:id="@+id/autoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionThreshold="1"
android:completionHint="Search for a city"
android:inputType="text"
android:imeOptions="actionSearch"
android:textColor="#000000"
android:textSize="16sp"
android:hint="Enter city name" />
This will create an AutoCompleteTextView field with a unique ID, width and height set to match_parent and wrap_content respectively, a minimum completion threshold of 1 character, a completion hint of "Search for a city", input type set to text, IME option set to actionSearch, text color set to black, text size set to 16sp and a hint text of "Enter city name". You can customize these attributes based on your requirements.


Programming Code:

Following code write in: MainActivity.java
package com.go2collage.practical_10;

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[] = {"RDBMS","Programming with Python", "Capstone Project", "Web Application Development", "Data Structure",
"Programming with C", "Entrepreneurship Development", "Advance Java", "Object Oriented Programming with C++"};

@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(2);
autoCompleteTextView.setAdapter(adapter);

}
}

Following code write in: activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_margin="20dp">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/logoTxt"
android:text="go2collage"
android:textAlignment="center"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="20dp"
android:layout_marginBottom="50dp"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="HardcodedText" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sixth Semester Subjects"
android:id="@+id/nameTxt"
android:textStyle="bold"
android:textSize="20sp"
android:textColor="@color/black"
android:layout_marginBottom="25dp"
android:layout_below="@+id/logoTxt"
android:textAlignment="center"
tools:ignore="HardcodedText" />

<AutoCompleteTextView
android:id="@+id/autoCompleteTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/nameTxt"
android:hint="Enter Subject name"
android:textColor="@color/black"
android:textColorHint="#78909C"
android:textSize="20sp"
tools:ignore="HardcodedText" />

</RelativeLayout>

Output:



Post a Comment

0 Comments

Ad Code

Responsive Advertisement