2014-06-09 8 views
-4

J'essaie d'utiliser ListView pour afficher les données. Il peut montrer le texte comme l'image suivante. Je suis sûr que ça fonctionne.Le texte n'apparaissait pas sur la vue texte dans ListView

enter image description here

j'ajouter le titre en face de chaque texte. Je veux le montrer comme l'image suivante.

enter image description here

Mais il ne montre le titre comme suit

enter image description here

Le code de fitnessdata.xml est comme ce qui suit

<?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> 

Mais quand je change de RelativeLayout à LinearLayout , il peut montrer le texte comme le p suivant icture

enter image description here

Le code de définir dans le fichier JAVA est comme ce qui suit:

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

Le code de texte Ajouter des données est comme ce qui suit:

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); 

Pourquoi le texte didn ne montre pas dans le ListView?

Répondre

1

changement

android:layout_width="match_parent" 

à

android:layout_width="wrap_content" 

Pour votre textview dans la mise en page xml

savoir utiliser simplement cette mise en page

<?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

Merci pour votre aide! – Wun

+0

@wun Bienvenue, heureux de vous aider. –

Questions connexes