Note that there are some explanatory texts on larger screens.

plurals
  1. POlistviewitem height does not change to wrap content
    primarykey
    data
    text
    <p>I have a list activity with listviewitem layout. The listviewitem contains a textview, the porblem is that if the string in the textview is too long - e.g. 3 lines, then the listviewitem height does not change to wrap the content. I am using adapter for the listview.</p> <p>The problem happens only when inserting new items using the adapter!!!!!!</p> <p>Here are the layout and the adapter:</p> <pre><code>public class RecipeInstructionsListViewAdapter extends ArrayAdapter&lt;Instruction&gt; { private Context mContext; private ArrayList&lt;Instruction&gt; mItems; private LayoutInflater mInflater; public RecipeInstructionsListViewAdapter(Context context, int textViewResourceId,ArrayList&lt;Instruction&gt; items) { super(context,textViewResourceId,items); mContext=context; mItems=items; mInflater=(LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @Override public View getView(int position,View convertView,ViewGroup parent) { ViewHolder holder = new ViewHolder(); if(convertView == null) { convertView =mInflater.inflate(R.layout.recipes_instruction_list_single_view_entry, null); } if( super.getItem(position) != null ) { holder.instructionIndex = (TextView) convertView.findViewById( R.id.listUp_RecipeInstructionNumberTextBoxId ); holder.instructionText = (TextView) convertView.findViewById( R.id.listUp_RecipeInstructioTextTextBoxId ); holder.instructionImage = (ImageView)convertView.findViewById( R.id.listUp_RecipeInstructionImageViewId ); Typeface tf = Typeface.createFromAsset(mContext.getAssets(), "Eras_Bold.ttf"); holder.instructionIndex.setTypeface(tf); holder.instructionIndex.setTextSize(30); holder.instructionIndex.setTextColor( GlobalDefs.GetHeadlineColor() ); holder.instructionIndex.setText( Integer.toString(mItems.get(position).getIndex() ) ); tf = Typeface.createFromAsset(mContext.getAssets(), "Arial.ttf"); holder.instructionText.setTypeface(tf); holder.instructionText.setTextSize(14); holder.instructionText.setTextColor( Color.BLACK ); holder.instructionText.setText( mItems.get(position).getText() ); String imageLocation = mItems.get(position).GetInstructionImageLocation(); if( imageLocation != null ) { holder.instructionImage.setImageURI( Uri.parse( imageLocation ) ); holder.instructionImage.setVisibility( View.VISIBLE ); } else { holder.instructionImage.setVisibility( View.GONE ); } convertView.setTag(holder); convertView.setLayoutParams( new ListView.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); } else { } return convertView; } @Override public boolean isEnabled(int position) { return true; } static class ViewHolder { TextView instructionIndex; TextView instructionText; ImageView instructionImage; } } </code></pre> <p><strong>xml:</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/list_up" &gt; &lt;TextView android:id="@+id/listUp_RecipeInstructionNumberTextBoxId" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:textSize="30dip" /&gt; &lt;ImageView android:layout_height="19dp" android:layout_width="19dp" android:id="@+id/listUp_RecipeInstructionImageViewId" android:layout_alignParentTop="true" android:layout_alignParentRight="true" android:layout_marginRight="19dp" /&gt; &lt;TextView android:id="@+id/listUp_RecipeInstructioTextTextBoxId" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_toRightOf="@+id/listUp_RecipeInstructionNumberTextBoxId" android:layout_marginLeft="15dp" android:textSize="14dip" /&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload