How to set the height of a custom list item ...?

I have my own list view, which contains two text views and a button. I have customized the button style. In the list view, each line is not suitable for the correct display of my button. I want to change the height of a list item. How can i do this??

This is my list.

<ListView android:layout_width="fill_parent" android:scrollbars="none" android:footerDividersEnabled="false" android:minHeight="50dp" android:listSelector="#00000000" android:dividerHeight="0px" android:divider="#00000000" android:layout_height="fill_parent" android:layout_marginLeft="5dp" android:layout_marginTop="5dp" android:layout_marginRight="5dp" android:id="@+id/list_view" android:cacheColorHint="#00000000" android:background="#00000000" /> 

my custom xml view

 <?xml version="1.0" encoding="UTF-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:layout_width="150dp" android:layout_height="wrap_content" android:textColor="#808080" android:text="Subtitle 2" android:id="@+id/text1" android:layout_marginLeft="5dp" android:singleLine="true"/> <TextView android:layout_width="60dp" android:layout_height="wrap_content" android:textColor="#808080" android:text="$ 00.00" android:id="@+id/text2" android:singleLine="true"/> <Button android:layout_width="80dp" android:layout_height="25dp" android:background="@drawable/type10_subbg" android:text="Add" android:textSize="20dp" android:textStyle="bold" android:textColor="#153E7E" android:id="@+id/add" /> </LinearLayout> 

Here is my getView.

 @SuppressWarnings("unchecked") @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; pos = position; holder = new ViewHolder(); convertView = inflater.inflate(R.layout.type10_sub, null); holder.text1 = (TextView) convertView.findViewById(R.id.text1); holder.text2 = (TextView) convertView.findViewById(R.id.text2); holder.add = (Button) convertView.findViewById(R.id.add); holder.add.setTag(String.valueOf(position)); holder.add.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Button b = (Button)v; int tag = Integer.valueOf((String)b.getTag()); System.out.println("Added at "+tag); System.out.println("Data = "+((HashMap<String,Object>)list.get(tag)).get("text1").toString()); System.out.println("Price = "+((HashMap<String,Object>)list.get(tag)).get("text2").toString()); } }); holder.text1.setText(((HashMap<String,Object>)list.get(position)).get("text1").toString()); holder.text2.setText(((HashMap<String,Object>)list.get(position)).get("text2").toString()); convertView.setTag(holder); return convertView; } 

Thanks in advance....!

+4
source share
5 answers

convertedview.setlayoutparams(new Listview.setlayoutparams(width, height));

First put a LinearLayout instead of a ListView

and then edit it to ListView , otherwise it will not work. This is a trick.

+3
source

set minHeight in R.layout.type10_sub elements

+1
source

Its very simple layout_height at a new height for the user view simply indicates layout_height for the highest level element, in this case LinearLayout. Below I showed how to set it to 100dp

 <?xml version="1.0" encoding="UTF-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="100dp"> .... </LinearLayout> 
0
source

In linear layout give android: layout_height = "100dp" instead of wrap_content

0
source

using:

 if(convertView == null){ convertView = inflater.inflate(R.layout.type10_sub, parent); } 
0
source

All Articles