Android:在ListView中为ListView编写适配器

时间:2015-11-15 17:00:29

标签: java android listview android-arrayadapter

我正在编写一个应用程序,用图片,名称和简短说明显示膳食。如果按下一餐,它应该将listitem的大小扩展到 从此http://puu.sh/lmwKn/b5f6f1d54a.jpg获取此http://puu.sh/lmwJo/943f7349d3.jpg

现在要向ListView添加食物我写了一个MealAdapter,我不知道如何获得评论列表的视图

    @Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder viewHolder = null;

    if (convertView == null) {
        convertView = LayoutInflater.from(context).inflate(
                R.layout.gericht_list_layout, null);
        viewHolder = new ViewHolder();
        viewHolder.img = (ImageView) convertView.findViewById(R.id.gericht_image);
        viewHolder.name = (TextView) convertView.findViewById(R.id.gericht_title);
        viewHolder.descTxt = (TextView) convertView.findViewById(R.id.gericht_sub_title);
        viewHolder.comments = (ListView) convertView.findViewById(R.id.gericht_comments);
        convertView.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) convertView.getTag();
    }

    viewHolder.name.setText(data.get(position).name);
    viewHolder.descTxt.setText(data.get(position).subName);

    int id = convertView.getResources().getIdentifier(
            data.get(position).img, "drawable",
            context.getPackageName());
    viewHolder.img.setImageResource(id);

    return convertView;
}

这是布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">

<ImageView
    android:id="@+id/gericht_image"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_alignParentLeft="true"
    android:src="@drawable/no_image"
    />

<TextView
    android:id="@+id/gericht_title"
    android:layout_width="fill_parent"
    android:layout_height="75dp"
    android:layout_toRightOf="@+id/gericht_image"
    android:text="Kein Name"
    android:layout_marginLeft="15dp"
    android:layout_marginTop="20dp"
    android:textColor="#000000"
    android:textSize="25sp"
    />

<TextView
    android:id="@+id/gericht_sub_title"
    android:layout_width="fill_parent"
    android:layout_height="25dp"
    android:text="Keine genauere Beschreibung"
    android:layout_toRightOf="@+id/gericht_image"
    android:layout_marginTop="55dp"
    android:layout_marginLeft="30dp"
    android:gravity="center_vertical"
    />

<ListView
    android:id="@+id/gericht_comments"
    android:layout_width="fill_parent"
    android:layout_marginTop="100dp"
    android:layout_marginLeft="50dp"
    android:layout_height="0dp"
    />
</RelativeLayout>

所以我想绘制gericht_comments列表视图,但我不知道如何

0 个答案:

没有答案