2016-08-30 74 views
0

已花時間閱讀帖子,但沒有找到與遇到問題相關的任何內容。已創建ListView適配器工作行,但爲空白

有一個基於Android Marshmallow的應用程序啓動一個包含listview的佈局的活動。已經寫了一個自定義的適配器,它確實調用了getView方法,並且已經確認數據存在。從適配器的getView是:

ArrayList<HashMap<String,IncidentData>> localList; 
      mLayoutInflator = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      if (convertView == null) { 
       convertView = mLayoutInflator.inflate(R.layout.list_item_base_incident, parent,false); 
      } 
      mDateTimeText = (TextView)convertView.findViewById(R.id.date_time_text); 
      mAddressText = (TextView)convertView.findViewById(R.id.address_text); 
      mDistanceToText = (TextView)convertView.findViewById(R.id.distance_to_text); 
      mShortDescText = (TextView)convertView.findViewById(R.id.short_desc_text); 
      mGangRelatedText = (TextView)convertView.findViewById(R.id.gang_related_text); 
      //pop data 

      HashMap<String,IncidentData>incident2 = mID.get(position); 
      IncidentData id = incident2.get(incident2.keySet().iterator().next()); 

      mDateTimeText.setText(id.getDateTime()); 
      mAddressText.setText(id.getAddress()); 
      mDistanceToText.setText(String.valueOf(id.getDistance())); 
      mShortDescText.setText(id.getShortDesc()); 
      mGangRelatedText.setText(id.getGangRelated()); 
      Log.d(LOG_TAG,"SHORT DESC - "+ id.getShortDesc()); 
      return convertView; 
} 

日誌消息顯示getView正確處理hashmap中的每個條目。問題是數據沒有出現在列表視圖中,但是,列表視圖確實顯示了大量數據的空白條目的正確數量。 屏幕布局如下: incident_layout_base.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <ListView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/incident_list_view"/> 
</LinearLayout> 

和列表視圖內容的佈局是:

<?xml version="1.0" encoding="utf-8"?> 
    <android.support.v7.widget.GridLayout 
     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:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:columnCount="1"> 

     <TextView 
      android:id="@+id/date_time_text" 
      app:layout_columnWeight="1" 
      tools:text="[email protected]"/> 
     <TextView 
      android:id="@+id/address_text" 
      app:layout_columnWeight="1" 
      tools:text="SAN FERNANDO BLVD AND ALAMEDA AVE"/> 
     <TextView 
      android:id="@+id/distance_to_text" 
      app:layout_columnWeight="1" 
      tools:text="1"/> 
     <TextView 
      android:id="@+id/short_desc_text" 
      app:layout_columnWeight="1" 
      tools:text="Murder"/> 
     <TextView 
      android:id="@+id/gang_related_text" 
      app:layout_columnWeight="1" 
      tools:text="gang related"/> 
</android.support.v7.widget.GridLayout> 

該應用程序啓動的意圖的處理包含列表視圖的顯示。意圖調用setContentView,獲取數據,實例化自定義適配器並在其上調用setAdapter。

想法讚賞

+0

在你的TextViews中爲什麼它是「工具:文本」?它不應該是「android:text」嗎? –

+0

不,這行支持tools.text - xmlns:tools =「http://schemas.android.com/tools」 – MrMagoo

+0

如果我沒有弄錯,工具屬性不適用於運行時:http://tools.android。 COM /提示/佈局設計時的屬性。 –

回答

0

找到沒有數據顯示的問題。背景和文字顏色默認爲白色。所以,當數據在那裏時,yoiu看不到它。

相關問題