ListActivity help

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

ListActivity help

Postby soch » Thu Jan 07, 2010 11:55 pm

Hi,

I am working on a listactivity and I want each of my rows to have this layout:

icon1 text1
text2
text3 icon2 icon3

I am using cutom layout and implemented row.xml for the rows. I have played with different layouts but can't produce the desired results. Can anyone please suggest what layout parameters should I use.

Here is my row.xml posted:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  5.  
  6.    android:layout_width="fill_parent"
  7.  
  8.    android:layout_height="?android:attr/listPreferredItemHeight"
  9.  
  10.    android:padding="6dip">
  11.  
  12.     <ImageView
  13.  
  14.        android:id="@+id/icon"
  15.  
  16.        android:layout_width="wrap_content"
  17.  
  18.        android:layout_height="fill_parent"
  19.  
  20.        android:layout_marginRight="6dip"
  21.  
  22.        android:src="@drawable/icon" />
  23.  
  24.     <LinearLayout
  25.  
  26.        android:orientation="vertical"
  27.  
  28.        android:layout_width="0dip"
  29.  
  30.        android:layout_weight="1"
  31.  
  32.        android:layout_height="fill_parent">
  33.  
  34.         <TextView
  35.  
  36.            android:id="@+id/toptext"
  37.  
  38.            android:layout_width="fill_parent"
  39.  
  40.            android:layout_height="0dip"
  41.  
  42.            android:layout_weight="1"
  43.  
  44.            android:gravity="center_vertical"
  45.  
  46.            android:cacheColorHint="#00000000"
  47.  
  48.        />
  49.  
  50.         <TextView
  51.  
  52.            android:layout_width="fill_parent"
  53.  
  54.            android:layout_height="0dip"
  55.  
  56.            android:layout_weight="1"
  57.  
  58.            android:id="@+id/bottomtext"
  59.  
  60.            android:singleLine="true"
  61.  
  62.            android:ellipsize="marquee"
  63.  
  64.        />
  65.  
  66.        
  67.  
  68.          <TextView
  69.  
  70.            android:layout_width="fill_parent"
  71.  
  72.            android:layout_height="0dip"
  73.  
  74.            android:layout_weight="1"
  75.  
  76.            android:id="@+id/phonetext"
  77.  
  78.            android:singleLine="true"
  79.  
  80.            android:ellipsize="marquee"
  81.  
  82.        />
  83.  
  84.        
  85.  
  86.        
  87.  
  88.    
  89.  
  90.      <ImageView
  91.  
  92.        android:id="@+id/icon2"
  93.  
  94.        android:layout_width="wrap_content"
  95.  
  96.        android:layout_height="wrap_content"
  97.  
  98.        android:src="@android:drawable/sym_action_call" android:layout_gravity="right"/>
  99.  
  100.        
  101.  
  102.         <ImageView
  103.  
  104.        android:id="@+id/icon3"
  105.  
  106.        android:layout_width="wrap_content"
  107.  
  108.        android:layout_height="wrap_content"
  109.  
  110.        android:src="@android:drawable/ic_dialog_map" android:layout_gravity="right"/>
  111.  
  112.    </LinearLayout>    
  113.  
  114.        
  115.  
  116.              
  117.  
  118.        
  119.  
  120. </LinearLayout>
  121.  
  122.  
  123.  
  124.  
Parsed in 0.007 seconds, using GeSHi 1.0.8.4
soch
Freshman
Freshman
 
Posts: 3
Joined: Thu Jan 07, 2010 11:46 pm

Top

Postby jwei512 » Fri Jan 08, 2010 12:05 am

Try

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2.  
  3.  
  4. <?xml version="1.0" encoding="utf-8"?>
  5.  
  6. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  7.  
  8.    android:layout_width="fill_parent"
  9.  
  10.    android:layout_height="?android:attr/listPreferredItemHeight"
  11.  
  12.    android:orientation="vertical"
  13.  
  14.    android:padding="6dip">
  15.  
  16.  
  17.  
  18.     <LinearLayout
  19.  
  20.         android:layout_width="fill_parent"
  21.  
  22.         android:layout_height="wrap_content"
  23.  
  24.         android:orientation="horizontal"
  25.  
  26.         android:padding="6dip" >
  27.  
  28.     <ImageView
  29.  
  30.        android:id="@+id/icon1"
  31.  
  32.        android:layout_width="wrap_content"
  33.  
  34.        android:layout_height="fill_parent"
  35.  
  36.        android:layout_marginRight="6dip"
  37.  
  38.        android:src="@drawable/icon" />
  39.  
  40.      <TextView
  41.  
  42.            android:id="@+id/text1"
  43.  
  44.            android:layout_width="fill_parent"
  45.  
  46.            android:layout_height="0dip"
  47.  
  48.            android:layout_weight="1"
  49.  
  50.            android:gravity="center_vertical"
  51.  
  52.            android:cacheColorHint="#00000000"
  53.  
  54.        />
  55.  
  56.     </LinearLayout>
  57.  
  58.  
  59.  
  60.     <LinearLayout
  61.  
  62.         android:layout_width="fill_parent"
  63.  
  64.         android:layout_height="wrap_content"
  65.  
  66.         android:orientation="horizontal"
  67.  
  68.         android:padding="6dip" >
  69.  
  70.         <TextView
  71.  
  72.            android:id="@+id/text2"
  73.  
  74.            android:layout_width="fill_parent"
  75.  
  76.            android:layout_height="0dip"
  77.  
  78.            android:layout_weight="1"
  79.  
  80.            android:gravity="center_vertical"
  81.  
  82.            android:cacheColorHint="#00000000"
  83.  
  84.        />
  85.  
  86.     </LinearLayout>
  87.  
  88.        
  89.  
  90.     <LinearLayout
  91.  
  92.         android:layout_width="fill_parent"
  93.  
  94.         android:layout_height="wrap_content"
  95.  
  96.         android:orientation="horizontal"
  97.  
  98.         android:padding="6dip" >
  99.  
  100.      <TextView
  101.  
  102.            android:id="@+id/text3"
  103.  
  104.            android:layout_width="fill_parent"
  105.  
  106.            android:layout_height="0dip"
  107.  
  108.            android:layout_weight="1"
  109.  
  110.            android:singleLine="true"
  111.  
  112.            android:ellipsize="marquee" />
  113.  
  114.      <ImageView
  115.  
  116.        android:id="@+id/icon2"
  117.  
  118.        android:layout_width="wrap_content"
  119.  
  120.        android:layout_height="wrap_content"
  121.  
  122.        android:src="@android:drawable/sym_action_call" android:layout_gravity="right"/>
  123.  
  124.       <ImageView
  125.  
  126.        android:id="@+id/icon3"
  127.  
  128.        android:layout_width="wrap_content"
  129.  
  130.        android:layout_height="wrap_content"
  131.  
  132.        android:src="@android:drawable/ic_dialog_map" android:layout_gravity="right"/>
  133.  
  134.    </LinearLayout>    
  135.  
  136.  
  137.  
  138. </LinearLayout>
  139.  
  140.  
  141.  
  142.  
Parsed in 0.008 seconds, using GeSHi 1.0.8.4


That should work hopefully.
- jwei

http://thinkandroid.wordpress.com
Examples, Code, and Tutorials
jwei512
Senior Developer
Senior Developer
 
Posts: 135
Joined: Mon Jul 27, 2009 9:35 pm
Location: Palo Alto, CA

Postby soch » Fri Jan 08, 2010 12:19 am

Thanks for a quick response. But, this layout is not showing anything.
soch
Freshman
Freshman
 
Posts: 3
Joined: Thu Jan 07, 2010 11:46 pm

Postby jwei512 » Fri Jan 08, 2010 12:33 am

Okay well it's probably because you have to go back and make some small adjustments. I just copy pasted a lot of what you had in your original thing into a layout that I know will work (in your original layout, you had one vertical linear layout and all of your children elements in that one linear layout... and so obviously it wasn't going to give you what you wanted), but you're going to have to make the small adjustments to what I gave you and get it to show the stuff you want.

For instance, why are the heights of your TextView's 0dip? If that's the case... then text will probably not show up as your View has no height.

Just keep playing around with it from there and it should work.
- jwei

http://thinkandroid.wordpress.com
Examples, Code, and Tutorials
jwei512
Senior Developer
Senior Developer
 
Posts: 135
Joined: Mon Jul 27, 2009 9:35 pm
Location: Palo Alto, CA

Postby icobasco » Wed Jan 13, 2010 10:50 am

Hi,

cause I'm in love with RelativeLayout ;) I suggest to use it instead of LinearLayout... but it really depends on your taste and parent's layout (too many of them cause a bad stack overflow).

In your case you can use 1 RelativeLayout with 2 LinearLayout for inside:
- the 1st (ll_one) with icon1 and text1 toRightOf="icon1"
- the text2 below="ll_one"
- the 2nd LinearLayout below="text2" and with icon3 aligned right, icon2 toLeftOf="icon3" and text3 toLeftOf="icon2"

I cannot try it now, sorry, but those would be my steps :)

Hope it can help you a little
User avatar
icobasco
Senior Developer
Senior Developer
 
Posts: 108
Joined: Thu Jun 04, 2009 11:12 am
Location: Italy

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Majestic-12 [Bot] and 2 guests