Я хотел бы показать строки в соответствии с моими данными.Например, я буду динамически создавать 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>