1

There is a need to displaying two views in a single ListView Row . How it is possible in android. Please help me.

enter image description here

nitin tyagi
  • 1,176
  • 1
  • 19
  • 52
  • use custom lsitview..http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/ – RajaReddy PolamReddy Oct 15 '12 at 05:14
  • I am working on a chat Application. i am showing friend's in a listView . Now I want to showing two friends with their online status(online / offline image ) in a single rows. I have attach an image. I want to doing like that image. – nitin tyagi Oct 15 '12 at 05:15
  • you have to use custom list adapter. refer this :http://www.ezzylearning.com/tutorial.aspx?tid=1763429 – Ramindu Weeraman Oct 15 '12 at 05:19
  • thanks for reply to all. My problem is that I used SimpleCursorAdapter for filling listItem , Now i am getting only single entery on calling getView method . So i am able to fill only half part of ListView row. Now next calling of getView calls another row of ListView. but i want to add second friend in previous list row like the image which i added , Please help me. – nitin tyagi Oct 15 '12 at 05:25

2 Answers2

1

You can use custom layout for your lists , here is example which is using imageview and textview in a single row. Row.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="horizontal"
      >
  <ImageView
  android:id="@+id/icon"
  android:padding="2dip"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:src="@drawable/ok"
  />
  <TextView
  android:id="@+id/label"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:textSize="40sp"
  />
  </LinearLayout>

Here is java code ,this is an activity's onCreate extending ListActivity.

public void onCreate(Bundle icicle) {
  super.onCreate(icicle);
  setContentView(R.layout.main);
  setListAdapter(new ArrayAdapter<String>(this,R.layout.row, R.id.label,items));
  selection=(TextView)findViewById(R.id.selection);
  }
Vins
  • 4,089
  • 2
  • 35
  • 50
  • Thanks for reply . You use ArrayAdapter for this but i am using SimpleCursorAdaptor for filling the data in listview So i got only one entery at a time inside getView() , next time calling of getView generate another row of ListView. So I am not able to fill data like that image. – nitin tyagi Oct 16 '12 at 12:01
  • Yo want to fill data for each row dynamically ? – Vins Oct 17 '12 at 04:22
  • yes . I want to fill data for each row dynamically and one thing is that i have two shell in each row like that image posted above. – nitin tyagi Oct 17 '12 at 04:27
  • I think you have to use layout inflator for this. Im not sure. – Vins Oct 17 '12 at 04:53
0

Use GridView and add this to the parameters.

android:numColumns="2"

Check this first and this Kinda helped me too with the same problem. :)

Community
  • 1
  • 1
Sudhanshu
  • 735
  • 1
  • 8
  • 20