android - How to set custom list view item's height? [Solved] -


there lot of questions no 1 me. have tried in class adapter view.setminimumheigth(minheigth) didn't work. tried view view = inflater.inflate(r.layout.list_note_item,parent); app crashed; 1 close enough : view view = inflater.inflate(r.layout.list_note_item,parent,false); items had same height showed first textview , not second. how can this?

here's list_item xml layout file

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="@dimen/note_item_heigth" android:orientation="vertical" >      <textview         android:id="@+id/textview_title"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:textcolor="#000000"         android:background="#ffffff"         android:textsize="16sp"         />      <textview         android:id="@+id/textview_note"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:textcolor="#808080"         android:background="#ffffff"         android:textsize="14sp"         android:maxlength="80"          /> 

and listview xml layout:

<listview      android:id="@+id/list_notes"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:divider="@android:color/transparent"     android:dividerheight="@dimen/space_between_items"     ></listview> 

and class adapter

public view getview(int position, view convertview, viewgroup parent) {     layoutinflater inflater = (layoutinflater)context.getsystemservice(context.layout_inflater_service);     view view = inflater.inflate(r.layout.list_note_item,parent,false);     textview title = (textview)view.findviewbyid(r.id.textview_title);     textview note = (textview)view.findviewbyid(r.id.textview_note);     title.settext("test");     note.settext("test"); 

thanks in advance!

if linearlayout must use @dimen/note_item_heigth make textviews share given height:

<textview     android:id="@+id/textview_title"     android:layout_width="match_parent"     android:layout_height="0dp"     android:layout_weight="1"     android:textcolor="#000000"     android:background="#ffffff"     android:textsize="16sp" />  <textview     android:id="@+id/textview_note"     android:layout_width="match_parent"     android:layout_height="0dp"     android:layout_weight="1"     android:textcolor="#808080"     android:background="#ffffff"     android:textsize="14sp"     android:maxlength="80" /> 

note: may need lower textsize, text fit textview.


otherwise, if don't care list item's height can set linearadapter wrap_content , done it:

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -