1

I have a code made by Fedor, it can be found "here".

The first image is what I have now,

and the second image is what I want to accomplish.

Can someone guide me with this. I have been struggling for days trying to solve this problem. Please help me, Thanks in advance!

enter image description here

enter image description here

Community
  • 1
  • 1
Kuwame Brown
  • 533
  • 1
  • 10
  • 22

3 Answers3

1

Here is an example of something similar. You have to create a custom adapter for your ListView.

http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/

You can probably use most of that example. Just change the row.xml to create tha layout you want and the getView() in the adapter.

manuel
  • 837
  • 6
  • 18
0

You just need to modify the list item layout (in item.xml) to have another ImageView.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="wrap_content">
    <ImageView android:id="@+id/image1" android:layout_width="50dip" 
        android:layout_height="50dip" android:src="@drawable/stub" 
        android:scaleType="centerCrop" /> 
    <ImageView android:id="@+id/image2" android:layout_width="50dip" 
        android:layout_height="50dip" android:src="@drawable/stub" 
        android:scaleType="centerCrop" /> 
    <TextView android:id="@+id/text" android:layout_width="fill_parent" 
        android:layout_height="wrap_content" android:layout_weight="1" 
        android:layout_gravity="left|center_vertical" android:textSize="20dip" 
        android:layout_marginLeft="10dip" /> 
</LinearLayout>

and modify LazyAdapter's getView() method to add support for the second ImageView.

Robby Pond
  • 73,164
  • 16
  • 126
  • 119
  • I tried to play around with the LazyAdapter.class but what should I exactly have to change there to solve my problem? – Kuwame Brown Mar 29 '11 at 17:12
0

A tutorial for creating a Custom ListView can be found here: http://justcallmebrian.com/?p=139

Just need to change the XML layout for each item to have 2 ImageViews like Robby said. Then in your getView of your Adapter (LazyAdapter if you followed along with the other people's answers) you should have something like this:

ImageView image1 = (ImageView) findViewById(R.id.image1); image1.setResource(R.drawable.icon1); ImageView image2 = (ImageView) findViewById(R.id.image2); image2.setResource(R.drawable.icon2); TextView text = (TextView)findViewById(R.id.text); text.setText("I have 2 images");

The tutorial I pasted earlier depicts a way to make the generation of the list dynamic (i.e. not having the resource of R.drawable.icon1/2 and not having the text for your Text images). Something like this may work (assuming you have a Model class that will hold all 3 pieces of information):

int resid1 = context.getResources().getIdentifier("com.domain.sub:drawable/" + myList.get(position).getImage1Name, null, null);
ImageView image1 = (ImageView) findViewById(R.id.image1);
image1.setResource(resid1);
int resid2 = context.getResources().getIdentifier("com.domain.sub:drawable/" + myList.get(position).getImage2Name, null, null);
ImageView image2 = (ImageView) findViewById(R.id.image2);
image2.setResource(resid2);
TextView text = (TextView)findViewById(R.id.text);
text.setText(myList.get(position).getText());

Of course the snippet above assumes you have an ArrayList called myList that also getters to get the image names and the text to display.

Brian Call
  • 26
  • 1