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....!
source share