Listview

Android Custom Dynamic Listview –part3

Android simple tutorial for adding data into listview at runtime and change the listview content dynamically.

Android Custom Listview Tutorial - Part 2

Moving ahead from first part Custom List view,  we are going to discuss three things.

1.Adding background colors to Listview

2.Adding different Divider color.

3.Triggering action on listview click.

Step 1:

Listview Background Color

Adding Custom Background color to listview . For an elegance look for an application the listview color play a key role.

[sourcecode language="java"]

convertView.setBackgroundColor((position & 1) == 1 ? Color.WHITE : Color.LTGRAY);

[/sourcecode]

Android Custom Listview Tutorial- part 1

The simple android custom listview can assist only a single string, where its not possible to use them on all application. This leads to create custom list view example tutorial .
Step 1:
Add a normal listview in the main.xml layout and make sure u set the layout width as fill parent.
Main.xml

[sourcecode language="xml"]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">

<TextView android:id="@+id/TextView01" android:layout_height="wrap_content" android:text="List of Country &amp; their denotation" android:textStyle="normal|bold" android:gravity="center_vertical|center_horizontal" android:layout_width="fill_parent"></TextView>
<ListView android:id="@+id/ListView01" android:layout_height="wrap_content"
android:layout_width="fill_parent">
</ListView>
</LinearLayout>

[/sourcecode]

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 ListView Multiple Choice Example

In android listview we can able to select more then one option at a time in list.
Here is a simple example for how to select more then one option from list.
Multiple Choice ListView Example :-
xml file
[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">
<ListView android:id="@+id/ListView01" android:layout_he

Android Listview Onclick

By using setOnClickItemListener() we can get the clicked item in android listview.

Android Listview Example

Here we are going to see about a simple listview example using String arrays to display in list.

Syndicate content