Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android listView as the listView from iPhone

I would like to implement an ListView similar to one form the iPhone. Here is the image

The first element of the table is an image and the others are text plus arrow.

I know how to use an custom image adapter but only for an unique customization, not to customize each row.

That information is static, I should only have the possibility to click the desired element.

Thank you very much.

like image 897
Milos Cuculovic Avatar asked Jan 29 '26 11:01

Milos Cuculovic


1 Answers

I have found the solution,

I can use a header for the list view and a customized borders. Here is an example:

listview_border.xml in drawable folder:

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="4dp" android:color="#FFFFFFFF" />
<padding android:left="7dp" android:top="7dp"
        android:right="7dp" android:bottom="7dp" />
<corners android:radius="15dp" />
<solid android:color="#FFFFFFFF"/>
</shape> 

for the listview, set:

 android:background="@drawable/listview_border"

Then for the hedser, create a listviaw_header.xml in layouts:

<?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" >

   <ImageView
       android:id="@+id/imageView1"
       android:layout_width="128dp"
       android:layout_height="wrap_content"
       android:src="@drawable/contact_image_fr"
       android:layout_marginLeft="10dp" />

</LinearLayout> 

Then set the header:

ListView contact = (ListView) findViewById(R.id.contactListView);


    View header = getLayoutInflater().inflate(R.layout.contact_listview_header, null);

    contact.addHeaderView(header);  

And that's all. Enjoy...

like image 119
Milos Cuculovic Avatar answered Jan 31 '26 01:01

Milos Cuculovic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!