Listview里面只有一个Element

2024-05-12

您好,我正在尝试将列表视图放入列表视图中的列表视图中。 唯一的问题是只有第一个列表视图正确显示所有元素。 此后的每个列表视图仅包含一个元素。

UPDATE:

创建我自己的不可滚动列表视图解决了这个问题。https://stackoverflow.com/a/24629341/3713144 https://stackoverflow.com/a/24629341/3713144

这是一些代码:

Activity_anlagen_details.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout

   xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/DrawerLayout"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:elevation="7dp">

   <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical">


       <include
          android:id="@+id/tool_bar"
          layout="@layout/tool_bar"></include>

      <TextView
          android:id="@+id/anlagenName_textview"
          android:layout_width="0dp"
          android:layout_height="60dp"
          android:gravity="center|center_vertical"
          android:padding="3dip"
          android:singleLine="true"
          android:textAppearance="?android:attr/textAppearanceLarge" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="4dp"
        android:background="#424242" />

    <ListView
        android:id="@+id/listChecklisten"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

<android.support.v7.widget.RecyclerView
    android:id="@+id/RecyclerView"
    android:layout_width="320dp"
    android:layout_height="match_parent"
    android:layout_gravity="left"

    android:background="#ffffff"
    android:scrollbars="vertical">

    </android.support.v7.widget.RecyclerView>
</android.support.v4.widget.DrawerLayout>

anlagen_checklisten_listview.xml:

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

<TextView
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:id="@+id/checkliste_name"
    android:layout_gravity="center_horizontal"
    android:gravity="center|center_vertical"/>

<ListView
    android:id="@+id/listChecklistenPunkte"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

</LinearLayout>

等等...

我现在想做的是为所有列表视图设置一个 ArrayAdapter:

Anlagen详情活动:

...
long anlagenId = getIntent().getLongExtra("anlagen_id", 0);
Log.d(logger, "Details for Anlage: " + anlagenId);
LocalAnlagenAccessor accessor = new LocalAnlagenAccessor(this);
Anlage anlage = accessor.readAnlage(anlagenId);
TextView anlagenName = (TextView) findViewById(R.id.anlagenName_textview);
anlagenName.setText(anlage.getName());
ListView listView = (ListView) findViewById(R.id.listChecklisten);
AnlagenChecklistenAdapter adapter = new AnlagenChecklistenAdapter(this);
listView.setAdapter(adapter);
adapter.addAll(anlage.getChecklisten());
...

AnlagenChecklistenAdapter:

...
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View checklisteView = inflater.inflate(R.layout.anlagen_checklisten_listview, parent, false);
    TextView checklisteName = (TextView) checklisteView.findViewById(R.id.checkliste_name);
    checklisteName.setText(getItem(position).getArt());
    ListView listView = (ListView) checklisteView.findViewById(R.id.listChecklistenPunkte);
    AnlagenChecklistenPunktAdapter adapter = new AnlagenChecklistenPunktAdapter(checklisteView.getContext());
    listView.setAdapter(adapter);
    adapter.addAll(getItem(position).getChecklistenPunkte());
    return checklisteView;
}
...

对于另一个列表视图也是如此。 我在这里做错了什么?


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Listview里面只有一个Element 的相关文章

随机推荐