列表视图中的空行

时间:2017-12-18 10:40:35

标签: android listview

我创建了一个与适配器关联的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;
    }
}

2 个答案:

答案 0 :(得分:0)

您的父级布局的高度为match_content,请将其设为wrap_content。您的一行可能覆盖整个屏幕。

答案 1 :(得分:0)

试试这个

tester.type_group!
tester.type_group? # => true

Tester.type_group # SELECT "testers".* FROM "testers" WHERE "testers"."tester_type" = $1  [["tester_type", 2]]
# or,
Tester.where(tester_type: :group) # SELECT "testers".* FROM "testers" WHERE "testers"."tester_type" = $1  [["tester_type", 2]]