Sei sulla pagina 1di 21

Practical Works:

Basic Elements of Android


Part 2
Input Data using EditText and Spinner
EditText
XML LAYOUT
Put “Hint” in every EditText
Java code
Java code (….continued….)
Run on Emulator
AutoCompleteTextView
In Android,  AutoCompleteTextView  is a view i.e similar to EditText, except that it
displays a list of completion suggestions automatically while the user is typing.
• A list of suggestions is displayed in drop down menu from which user can choose
an item which actually replace the content of Editbox with that.
Using Array Adapter To Display Text Values In AutoCompleteTextView:
• To display the Array content in an  AutoCompleteTextView we need to
implement Adapter. In AutoCompleteTextView we mainly display text values so
we use Array Adapter for that.
• ArrayAdapter In Android is used when we need list of single type of items which
is backed by an Array. For example, list of phone contacts, countries or names
New File: AutoCompleteTextView
XML Layout
Java Code
MultiAutoCompleteTextView

AutoCompleteTextView
AutoCompleteTextView

MultiAutoCompleteTextView
Spinner
1.  Spinner provides a quick way to select one value from a
set of values.
2. Android spinners are nothing but the drop down-list
seen in other programming languages.
3. In a default state, a spinner shows its currently selected
value.
4. It provides a easy way to select a value from a list of
values.
Spinn
er
Reuse this code inside the XML file

<Spinner
android:id="@+id/simpleSpinner"
android:layout_width="201dp"
android:layout_height="97dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="152dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Java file

Ensure it is added
Java file (..continued)..
Java file (..continued)..

Outside onCreate()
Tutorial

1. Design your own app, ensure it involves minimum 5


components, from Lab1 and Lab2
2. Write your java code for actions on the components
3. Run your app on an emulator or device
4. Show to your lecturer

Potrebbero piacerti anche