2011-11-08 15 views
1

私はlistviewitemレイアウトのリストアクティビティを持っています。 listviewitemにはtextviewが含まれていますが、textviewの文字列が長すぎると3行の場合、リストビュー項目の高さは内容をラップするために変更されません。私はリストビューのためにアダプタを使用しています。listviewitemの高さがコンテンツを囲むように変更されない

アダプターを使用して新しいアイテムを挿入するときに問題が発生します!!!!!!

public class RecipeInstructionsListViewAdapter extends ArrayAdapter<Instruction> 
{ 
    private Context mContext; 
    private ArrayList<Instruction> mItems; 
    private LayoutInflater mInflater; 

    public RecipeInstructionsListViewAdapter(Context context, int textViewResourceId,ArrayList<Instruction> 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; 
    } 
} 

のxml::私はあなたが(LayoutParams.FILL_PARENT、LayoutParams.FILL_PARENT)の代わりに使うべきだと思う

<?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="fill_parent" 
    android:background="@drawable/list_up" > 

    <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" /> 

    <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" /> 

    <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" /> 

</LinearLayout> 

答えて

0

(LayoutParams.FILL_PARENTここ

は、レイアウトやアダプタです、LayoutParams.WRAP_CONTENT)。

+0

動作しません...その難しい質問...新しい項目を挿入する場合にのみ発生します。文字列でアダプタを初期化すると、その動作は完璧です... – Yoav

+0

次の投稿が見つかりましたhttp://stackoverflow.com/questions/2197744/android-textview-text-not-getting-wrapped – Yoav

関連する問題