Listview inside Listview only one item

Hi I am trying to put a listview inside a listview inside a listview. The only problem is that only the first list displays all items correctly. Each list after that contains only one item.

UPDATE:

Making my own scrolling list fixes the problem. Stackoverflow question

Here's some code:

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>

      

etc.

Now I am trying to set ArrayAdapter for all viewlists:

AnlagenDetailsActivity:

...
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;
}
...

      

The same happens for another list. What am I doing wrong here?

+3


source to share





All Articles