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

4
  • use custom lsitview..androidhive.info/2012/02/… Oct 15, 2012 at 5: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. Oct 15, 2012 at 5:15
  • you have to use custom list adapter. refer this :ezzylearning.com/tutorial.aspx?tid=1763429 Oct 15, 2012 at 5: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. Oct 15, 2012 at 5:25

2 Answers 2

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);
  }
4
  • 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. Oct 16, 2012 at 12:01
  • Yo want to fill data for each row dynamically ?
    – Vins
    Oct 17, 2012 at 4: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. Oct 17, 2012 at 4:27
  • I think you have to use layout inflator for this. Im not sure.
    – Vins
    Oct 17, 2012 at 4: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. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.