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

Lab 8

This lab journal details the implementation of AutoCompleteTextView and Spinners in an Android application using Android Studio. The objective was to understand these components and their functionalities, including setting up a user interface and handling user interactions. The lab concluded successfully with a demonstration of the features and their intended use in the application.

Uploaded by

m faisal
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)
14 views4 pages

Lab 8

This lab journal details the implementation of AutoCompleteTextView and Spinners in an Android application using Android Studio. The objective was to understand these components and their functionalities, including setting up a user interface and handling user interactions. The lab concluded successfully with a demonstration of the features and their intended use in the application.

Uploaded by

m faisal
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

Software Applications for Mobile Devices Lab

SEL-448

Lab Journal: 8

Name: Muhammad Faisal


Class: BCE-8.
Enrollment no: 01-132182-036.
Submitted to : Eng. AMNA WAHEED
Lab No. 8
Autocomplete Textview & Spinners
Software Used: Android Studio
Objective:
 Understanding Autocomplete Textview in an Android Application
 Understanding of Spinners in an Android Application.
Introduction:
AutoComplete Textview:
Android AutoCompleteTextView is a editable text field, it displays a list of suggestions in a drop down
menu from which user can select only one suggestion or value. Android AutoCompleteTextView is the
subclass of EditText class. The MultiAutoCompleteTextView is the subclass of AutoCompleteTextView
class. Generally, the dropdown list of suggestions can be obtained from the data adaptor and those
suggestions will be appeared only after giving the number characters defined in the Threshold limit. The
Threshold property of AutoCompleteTextView is used to define the minimum number of characters the user
must type to see the list of suggestions.The dropdown list of suggestions can be closed at any time in case if
no item is selected from the list or by pressing the back or enter key.

Spinners in android application:


Spinners provide a quick way to select one value from a set. In the default state, a spinner shows its
currently selected value. Touching the spinner displays a dropdown menu with all other available values,
from which the user can select a new one.

Task No.1:

 Create a view that contains a ‘Spinner’ and an ‘AutoCompleteTextView’.


 Position the ‘AutoCompleteTextView’ above the ‘Spinner’ control.
 Add some values as string arrays in the values folder that will later be bound to the controls placed
earlier.
 For the ‘AutoCompleteTextView’ enter some country names in the string array and for the ‘Spinner’
some bachelor degree courses. Below the ‘AutoCompleteTextView’ place a button.
 Upon being clicked the button should display a message about the ‘Autocomplete’ item selected.
 Also when a ‘Spinner’ item is selected from the dropdown list, a message should display the item
that was selected.
Coding:
XML File:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView"
android:layout_width="242dp"
android:layout_height="23dp"
android:text=" "
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.693" />

<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.879" />
</androidx.constraintlayout.widget.ConstraintLayout>
Java File:
package com.example.lab8;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements
AdapterView.OnItemSelectedListener {
String[] arr = { "Paries,France", "PA,United States","Parana,Brazil",
"Padua,Italy", "Pasadena,CA,United States"};
String [] arr1 = {"EE", "CS", "BA", "CE"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AutoCompleteTextView autocomplete = findViewById(R.id.autoCompleteTextView);
ArrayAdapter<String> adapter = new ArrayAdapter<String>
(this,android.R.layout.select_dialog_item, arr);
autocomplete.setThreshold(2);
autocomplete.setAdapter(adapter);
Spinner spin = findViewById(R.id.spinner);
spin.setOnItemSelectedListener(this);
ArrayAdapter<String> sa = new ArrayAdapter<String>
(this,android.R.layout.simple_spinner_item, arr1);
sa.setDropDownViewResource(android.R.layout.simple_spinner_item);
spin.setAdapter(sa);
Button button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String str = autocomplete.getText().toString();
Toast.makeText(MainActivity.this,str, Toast.LENGTH_SHORT).show();
}
}); }
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(this,arr1[i], Toast.LENGTH_SHORT).show();}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}}
Output:

Conclusion:
In this lab, we learned about autocomplete text view and spinners in android applications. The main
objective of this lab is how to implement autocomplete text view and spinners in android applications and
also apply threshold in autocomplete text view. All the tasks were completed successfully.

You might also like