Edittext

Android ListView with Searchbox Sort items

This article is next step of Listexample. Here we have a search box which sorts the list view as when the content matches the list items.

Why do we need this?

Imagine that if we have 2K to 3K items in the listview, It will not be possible to  scrolldown till 2000th item.In this case this will be handy to cut short items.

To start with we add a edittext box and Listview added to LinearLayout.

[sourcecode language="xml"]

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical">

<EditText android:id="@+id/EditText01" android:layout_height="wrap_content" android:layout_width="fill_parent" android:hint="Search"></EditText><ListView android:id="@+id/ListView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" ></ListView>

</LinearLayout>

[/sourcecode]

Android EditorInfo Go, Search, Done, Next Example

There is always necessity to add extra keys apart from default keys available in virtual QWERTY keyboard. For instance we may need a direct search key by the side of edit text box in order to have direct triggering of Search actions.
For Instance to add a Search key we need to add this code, so that It may appear in the QWERTY board.

[sourcecode language="java"]
EditTextSample.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
[/sourcecode]

Android Edittext Inputtype

Edittext inputtype is used to set your input type for edittext.

Ex:- You can set your edittext inputtype as 'Phone'. So that user can able to type only numbers.

Android Edittext Hint

We can set edittext hint by using edittext 'android:hint' property.

Edittext hint is used to display a hint about the edittext.

Example: - When we are creating a login window we will create a textview & editext.

Textview is for input (“Enter the username”).

Editext is for output (“androidpeople”).

By using edittext hint we need not create a textview for input.

Android Edittext Single Line

We can set edittext to be a single line by using the property 'android:singleLine'.

When we type in more text in edittext it will wrap the content and create another line for the text.

Android Edittext Numeric

We can set edittext to only allow integer values using edittext property 'numeric'.

[sourcecode language="xml"]

<EditText android:text="435.569"
android:id="@+id/EditText01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numeric="integer|decimal" />

[/sourcecode]

Here the numeric is both 'interger & decimal'. So it will accept only the integer & decimal values.

Android Edittext Password

Here we are going to see about how to set edittext field to be a Password?
It is very simple to set editext field to Password...

[sourcecode language="css"]
<EditText android:id="@+id/EditText01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4435"
android:password="true" />
[/sourcecode]

We just need to set android:password=true to make your edittext to password.

The Output will look like

Android Text Color

In Android, we can set text color for textview, edittext, buttons, etc...

Example:-

Input

Output

Syndicate content