2017-12-18 303 views
1

我創建了一個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; 
    } 
} 
+0

你使用哪種適配器列表'getItemCount()'它不存在? – R2R

+0

分享ShoppingListAdapter的全部內容。 –

+0

我更新了帖子。這是我刪除儘可能多的後我只能發現什麼是行不通的適配器。 ? –

回答

0

試試這個

<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" /> 
+0

現在正在工作。非常感謝你。 –

+0

@TomaRadu高興地幫助你。祝你今天愉快。 –

0

你的父母佈局的高度match_content,使其WRAP_CONTENT。您的一行可能會覆蓋整個屏幕。

+0

當內容在屏幕上出現X字符串時出現X行(按行分隔),但它們是empy。 –

+0

你需要在xml中設置textview的textview。它將開始工作。 – Toyj