2016-08-30 11 views
0

投稿の閲覧に時間を費やしていて、発生した問題に関連するものが見つかりませんでした。ListViewアダプタの作成行は作成されていますが、空白です

リストビューを含むレイアウトを持つアクティビティを起動するAndroid Marshmallowベースのアプリケーションがあります。 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を示しています。問題は、データがリストビューに表示されないことですが、リストビューにはデータ量の正しい空白数が表示されます。次のように 画面レイアウトは次のとおりです。 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にはなぜ「ツール:テキスト」がありますか?それは "アンドロイド:テキスト"ではありませんか? –

+0

いいえ、この行はtools.text-xmlns:tools = "http://schemas.android.com/tools" – MrMagoo

+0

をサポートしています。私が誤っていないと、ツールの属性は実行時には適用されません:http://tools.android。 com/tips/layout-designtime-attributesにあります。 –

答えて

0

データが表示されないという問題が見つかりました。背景とテキストの色のデフォルトは白です。だから、そこにデータがある間、ヨーヨーはそれを見ることができませんでした。

関連する問題