2014-06-09 82 views
-4

我嘗試使用ListView來顯示數據。它可以顯示如下圖所示的文字。 我相信它正在工作。該文本沒有顯示在ListView中的文本視圖

enter image description here

我添加了標題中的每個文字的前面。我希望它顯示如下圖。

enter image description here

但只顯示標題類似於以下

enter image description here

fitnessdata.xml的代碼是類似如下

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <TextView android:id="@+id/Start_time_title" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textSize="12sp" 
      android:textStyle="bold" 
      android:text="@string/StartTime"/> 

    <TextView android:id="@+id/Start_time" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@+id/Start_time_title" 
      android:textSize="12sp"/> 

    <TextView android:id="@+id/End_time_title" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/Start_time_title" 
      android:textSize="12sp" 
      android:textStyle="bold" 
      android:text="@string/EndTime"/> 

    <TextView android:id="@+id/End_time" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@+id/End_time_title" 
      android:textSize="12sp"/> 

    <TextView android:id="@+id/distance_title" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/End_time_title" 
      android:textSize="12sp" 
      android:textStyle="bold" 
      android:text="@string/distance"/> 

    <TextView android:id="@+id/distance" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@+id/distance_title" 
      android:textSize="12sp"/>  

</RelativeLayout> 

但是,當我改變從RelativeLayoutLinearLayout ,它可以顯示如下p的文字icture。

enter image description here

在JAVA文件中定義的代碼是這樣的:

private static ListView fitness_data_list; 
private SimpleAdapter simpleadapter; 
private static ArrayList<HashMap<String, Object>> fitnessdatalist = new ArrayList<HashMap<String,Object>>(); 

添加數據文本的代碼是這樣的:

HashMap<String, Object> item = new HashMap<String, Object>(); 
item.put("startTime", FitnessData[times][0]); 
item.put("endTime", FitnessData[times][5]); 
item.put("distance", FitnessData[times][6]); 
item.put("stepcount", FitnessData[times][7]); 
fitnessdatalist.add(item); 
fitness_data_list.setAdapter(simpleadapter); 

爲什麼文本沒不顯示在ListView中?

回答

1

變化

android:layout_width="match_parent" 

android:layout_width="wrap_content" 

爲了您textview在XML佈局

即只需使用此佈局

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <TextView android:id="@+id/Start_time_title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="12sp" 
      android:textStyle="bold" 
      android:text="@string/StartTime"/> 

    <TextView android:id="@+id/Start_time" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@+id/Start_time_title" 
      android:textSize="12sp"/> 

    <TextView android:id="@+id/End_time_title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/Start_time_title" 
      android:textSize="12sp" 
      android:textStyle="bold" 
      android:text="@string/EndTime"/> 

    <TextView android:id="@+id/End_time" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@+id/End_time_title" 
      android:textSize="12sp"/> 

    <TextView android:id="@+id/distance_title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/End_time_title" 
      android:textSize="12sp" 
      android:textStyle="bold" 
      android:text="@string/distance"/> 

    <TextView android:id="@+id/distance" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@+id/distance_title" 
      android:textSize="12sp"/>  

</RelativeLayout> 
+0

感謝您的幫助! – Wun

+0

@wun歡迎,很高興幫助。 –

相關問題