2011-07-20 2 views
0

私のデータに基づいて行を表示したいと思います。たとえば、ループ内に10行を動的に作成し、この行は実際にはカスタム表示です。だから私は主な活動でそれを行う必要があります。あなたに私のやり方を教えてもらえますか?あなたはリストアダプタとラッパーを使用してカスタムビューを毎回膨らませることができループ内で取得するためにカスタムビューのインスタンスを取得するにはどうすればよいですか?

example.xml

<TableLayout 
android:id="@+id/tableLayout1" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android"> 
    <TableRow 
    android:id="@+id/tableRow1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
     <ImageView android:layout_height="wrap_content" android:src="@drawable/icon" android:id="@+id/imageView1" android:layout_width="wrap_content"></ImageView> 

     <LinearLayout android:layout_height="wrap_content" android:id="@+id/linearLayout1" android:orientation="vertical" android:layout_width="fill_parent"> 
     <TextView android:layout_height="wrap_content" android:layout_width="fill_parent" android:textAppearance="?android:attr/textAppearanceMedium" android:id="@+id/textView1" android:text="titletitletitletitletitletitle"></TextView> 
     <TextView android:text="DescriptionDescriptionDescription" android:id="@+id/textView2" android:layout_width="fill_parent" android:layout_height="wrap_content"></TextView> 
     </LinearLayout> 

    </TableRow> 
</TableLayout>` 

CustomView.java

public class CustomView extends LinearLayout 
{ 
    public CustomView(Context context, AttributeSet attrs) 
    { 
     super(context,attrs);  
     LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     View view=layoutInflater.inflate(R.layout.example,this); 
    } 

    private void init(Context context){ 

    } 
} 

main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
> 

    <ScrollView android:id="@+id/scrollView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    </ScrollView> 

</LinearLayout> 

答えて

関連する問題