1. Download our Official Android App: Forums for Android!

Apps Listview Image

Discussion in 'Android Development' started by amy97, Mar 21, 2011.

  1. amy97

    amy97 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    9
    Joined:
    Mar 1, 2011

    Mar 1, 2011
    9
    0
    5
    Hi,

    Can Ii use image graphics for list view and display text on that listview?

    Thanks!
    Amy
     

    Advertisement

  2. vovs

    vovs Member
    Rank:
    None
    Points:
    15
    Posts:
    31
    Joined:
    Feb 9, 2011

    Hi, You can use graphis and text in your list:

    rowlayout.xml
    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3.     android:layout_width="wrap_content" android:layout_height="wrap_content">
    4.     <ImageView android:id="@+id/icon" android:layout_height="wrap_content"
    5.         android:src="@drawable/icon" android:layout_width="22px"
    6.         android:layout_marginTop="4px" android:layout_marginRight="4px"
    7.         android:layout_marginLeft="4px">
    8.     </ImageView>
    9.     <TextView android:text="@+id/TextView01" android:layout_width="wrap_content"
    10.         android:layout_height="wrap_content" android:id="@+id/label"
    11.         android:textSize="30px"></TextView>
    12. </LinearLayout>
    and code:
    Code (Text):
    1. public class MyList extends ListActivity {
    2.     /** Called when the activity is first created. */
    3.     public void onCreate(Bundle bundle) {
    4.         super.onCreate(bundle);
    5.         // Create an array of Strings, that will be put to our ListActivity
    6.         String[] names = new String[] { "Sun", "Mercury", "Venus", "Earth",
    7.                 "Mars", "Jupiter", "Saturn", "Uranus" };
    8.         // Use your own layout and point the adapter to the UI elements which
    9.         // contains the label
    10.         this.setListAdapter(new ArrayAdapter<String>(this, R.layout.rowlayout,
    11.                 R.id.label, names));
    12.     }
    13. }
     

Share This Page

Loading...