-4
我嘗試使用ListView來顯示數據。它可以顯示如下圖所示的文字。 我相信它正在工作。該文本沒有顯示在ListView中的文本視圖
我添加了標題中的每個文字的前面。我希望它顯示如下圖。
但只顯示標題類似於以下
的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>
但是,當我改變從RelativeLayout
到LinearLayout
,它可以顯示如下p的文字icture。
在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中?
感謝您的幫助! – Wun
@wun歡迎,很高興幫助。 –