Home > Net >  LayoutInflating without result
LayoutInflating without result

Time:04-24

I'm trying to a add for each row in the cursor one instance of my ConstraintLayout and its childs to the linear layout (named verticalLayout), but there is no effect except closing the activity, no Exception. It's working fine for one instance, but with at least 2 its broken. Thanks for your help

The Code for adding it:

 private void addRows(){
        PersistenceManager.init(getApplicationContext());
        Cursor cursor = PersistenceManager.getInstance().getCursor();
        for(cursor.moveToFirst(); !cursor.isAfterLast();cursor.moveToLast()){
            ConstraintLayout child = (ConstraintLayout) getLayoutInflater().inflate(R.layout.track, null);
            linearLayout.addView(child);
        }
    }

And track.xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@ id/relativeLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    <TextView
        android:id="@ id/nameField"
        android:layout_width="55dp"
        android:layout_height="18dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="8dp"
        android:text="name"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@ id/distanceTv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="distance"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.125"
        app:layout_constraintStart_toEndOf="@ id/nameField"
        tools:ignore="MissingConstraints"
        tools:layout_editor_absoluteY="11dp" />

    <TextView
        android:id="@ id/upTv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="36dp"
        android:layout_marginTop="16dp"
        android:text="up"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@ id/nameField" />

    <TextView
        android:id="@ id/downTv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="36dp"
        android:layout_marginTop="12dp"
        android:text="down"
        app:layout_constraintStart_toEndOf="@ id/upTv"
        app:layout_constraintTop_toBottomOf="@ id/distanceTv" />

    <TextView
        android:id="@ id/dateTv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="12dp"
        android:text="date"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.171"
        app:layout_constraintStart_toEndOf="@ id/downTv"
        app:layout_constraintTop_toBottomOf="@ id/distanceTv" />

</androidx.constraintlayout.widget.ConstraintLayout>

CodePudding user response:

for(cursor.moveToFirst(); !cursor.isAfterLast();cursor.moveToLast())

This loop never terminates.

Change the moveToLast() to moveToNext() so that the cursor can reach "after last" state.

  • Related