我想为listactivity创建自定义行,每一行包含TitleList Of SubTitles
我的问题是:创建这些SubTitles的最佳方法是什么?我不能在row.xml中添加这些字幕,因为它们应该是动态的,取决于每一行。
我在写这个:

class Research{
        public String title;
        public ArrayList<String> subTitles;
    }
private class MyAdapter extends ArrayAdapter<Research> {

    public MyAdapter(Context context, int textViewResourceId,ArrayList<Research> items) {
        super(context, textViewResourceId, items);

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.row, null);
        }
        Research o = items.get(position);
        if (o != null) {
            TextView tt = (TextView) v.findViewById(R.id.textView1);
            if (tt != null) {
                tt.setText(o.title);
            }
        }

        /// THE PROBLEM STARTS HERE
        for(String subTitle: o.subTitles){
            TextView subTextView = new TextView(ResearchListActivity.this);
            subTextView.setText(subTitle);
            // where to add this view ? I don't see Layout here !
            parent.addView(subTextView);

        }
        //


        return v;
    }
}

行布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="vertical">
    <!-- Title -->
<TextView android:id="@+id/textView1" android:layout_width="fill_parent"
    android:text="" android:layout_height="wrap_content"
    android:textColor="#ddd" android:gravity="center" android:background="#7DB5C9"></TextView>

</LinearLayout>

明白了吗?
谢谢。

最佳答案

视图v是row.xml中的外部元素,即linearlayout。

    LinearLayout l = (LinearLayout)v;

然后在该布局上运行l.addview(…)。

09-26 09:04