4.1 Usnwnwer Input Controls
4.1 Usnwnwer Input Controls
User Interaction
and Navigation
Lesson 4
● Activity.getCurrentFocus()
● ViewGroup.getFocusedChild()
● EditText class
● Multiple lines of input
● Characters, numbers, and symbols
● Spelling correction
● Tapping the Return (Enter) key
starts a new line
● Customizable "Action" key
User Input Controls This work is licensed under a Creative
Android Developer Fundamentals Commons Attribution-NonCommercial 21
4.0 International License
Getting text
android:inputType="phone"
android:inputType="textAutoCorrect|textCapSentences"
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Do something in response to button click
}
});
For example:
Add Contact button in Contacts app
● Layout
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_fab_chat_button_white"
.../>
1. Right-click app/res/drawable
2. Choose New > Image Asset
3. Choose Action Bar and Tab Items
from drop down menu
4. Click the Clipart: image Experiment:
(the Android logo) 2. Choose New > Vector Asset
Toggle buttons
Switches
<Spinner
android:id="@+id/label_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Spinner>
<string-array name="labels_array">
<item>Home</item>
<item>Work</item>
<item>Mobile</item>
<item>Other</item>
</string-array>
// In onCreate()
Spinner spinner = (Spinner) findViewById(R.id.label_spinner);
if (spinner != null) {
spinner.setOnItemSelectedListener(this);
}
ArrayAdapter<CharSequence> adapter =
ArrayAdapter.createFromResource(
this, R.array.labels_array,
// Layout for each item
android.R.layout.simple_spinner_item);
TimePickerDialog DatePickerDialog