列表视图中的空行

我创建了一个listView,它与适配器关联。问题是即使我从创建的视图中设置了textview,行也显示为空。我提到listview中的行数是正确的。谢谢。列表视图中的空行

shopping_page_item

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 

xmlns:app="http://schemas.android.com/apk/res-auto"

android:layout_width="match_parent"

android:layout_height="match_parent">

<TextView

android:id="@+id/productTitle"

android:layout_width="0dp"

android:layout_height="47dp"

android:layout_marginEnd="32dp"

android:layout_marginStart="32dp"

android:layout_marginTop="16dp"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

适配器

public class ShoppingListAdapter extends ArrayAdapter<String> { 

public ShoppingListAdapter(Context context, String content[]) {

super(context, R.layout.shopping_page_item, content);

}

@Override

public View getView(final int position, View convertView, ViewGroup parent) {

if (convertView == null) {

convertView = LayoutInflater.from(getContext()).inflate(R.layout.shopping_page_item, parent, false);

}

TextView editText = convertView.findViewById(R.id.productTitle);

editText.setText(getItem(position).toString());

return convertView;

}

}

回答:

试试这个

<TextView 

android:id="@+id/productTitle"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginEnd="32dp"

android:layout_marginStart="32dp"

android:layout_marginTop="16dp"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent" />

回答:

你的父母布局的高度match_content,使其WRAP_CONTENT。您的一行可能会覆盖整个屏幕。

以上是 列表视图中的空行 的全部内容, 来源链接: utcz.com/qa/262598.html

回到顶部