我正在嘗試為游標中的每一行添加我的 ConstraintLayout 的一個實體及其子級到線性布局(名為verticalLayout),但除了關閉活動之外沒有任何效果,沒有例外。它在一個實體中作業正常,但至少有 2 個壞了。謝謝你的幫助
添加它的代碼:
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);
}
}
和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>
uj5u.com熱心網友回復:
for(cursor.moveToFirst(); !cursor.isAfterLast();cursor.moveToLast())
這個回圈永遠不會終止。
將 更改moveToLast()為moveToNext()使游標可以達到“after last”狀態。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/463386.html
上一篇:如何從應用程式中洗掉標簽
下一篇:在R中本地保存.json檔案
