2010-08-11 6 views
0

J'ai un problème lors de l'affichage des résultats d'une requête sql dans un ListView via SimpleCursorAdapter. Ceci est ma requête:Problème Android SimpleCursorAdapter/ListView

String sql = "" + 
"SELECT (Clients.firstname || \" \" || Clients.surname) AS client_name, " + 
    "Visits._id, " + 
    "Status.status, " + 
"strftime('%H:%M',time(sql_start_date,'unixepoch')) as start_time, " + 
"strftime('%H:%M',time(sql_end_date,'unixepoch')) as end_time " + 
"FROM " + 
     "Visits,Clients,Status " + 
"WHERE " + 
     "Visits.status = Status.remote_id " + 
"AND " + 
     "Visits.client_id = Clients.remote_id " + 
"AND " + 
    "Visits.sql_start_date > "+checkpoint+" " + 
"AND " + 
    "Visits.sql_end_date < "+endpoint; 

quand j'exécute cette requête j'obtiens un résultat typique mis comme ceci:

client_name |Visit._id|Status.status |start_time |end_time 
__________________________________________________________ 
Kevin Bradshaw|187  |Pending  |13:00  |14:00 
Peter Flynn |193  |Pending  |15:00  |16:30 

Je veux ce curseur sortie à un listview. Le problème que je rencontre est que je peux afficher le nom et l'état du client sans problèmes, mais les champs start_time et end_time restent vides.

mon code adaptateur curseur est la suivante:

Cursor cur = HomeScreen.this.application.getVisitsHelper().fetchVisits(); 
startManagingCursor(cur); 
// the desired columns to be bound  
String[] columns = new String[] {VisitsAdapter.KEY_CLIENT_FULL_NAME, VisitsAdapter.KEY_STATUS,VisitsAdapter.KEY_CLIENT_START_TIME, VisitsAdapter.KEY_CLIENT_END_TIME}; 

// the XML defined views which the data will be bound to 
int[] to = new int[] { R.id.name_entry,R.id.number_entry,R.id.start_time_display,R.id.end_time_display }; 

// create the adapter using the cursor pointing to the desired data as well as the layout information 
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(HomeScreen.this, R.layout.list_element, cur, columns, to); 

// set this adapter as ListActivity's adapter 
HomeScreen.this.setListAdapter(mAdapter); 

Et enfin ma mise en page xml (list_element.xml) est la suivante:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     > 
    <TextView 
    android_id="@+id/start_time_display" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="16dip" 
    android:textColor="#333333" 
    android:layout_marginLeft="14px" 
></TextView> 
    <TextView 
    android_id="@+id/end_time_display" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="16dip" 
    android:textColor="#333333" 
    android:layout_toRightOf="@+id/start_time_display" 
    android:layout_marginLeft="64px"></TextView> 
<TextView 
    android:id="@+id/name_entry" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="16dip" 
    android:textColor="#333333" 
    android:layout_marginLeft="94px" 
    android:layout_toRightOf="@+id/end_time_display"/> 
     <TextView 
    android:id="@+id/number_entry" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="14dip" 
    android:textColor="#666666" 
    android:layout_marginLeft="14px" 
    android:layout_below="@+id/name_entry" 
    /> 
</RelativeLayout> 

Donc ma question est, comment se fait une partie du code (c'est-à-dire le statut et le nom du client) est en cours de production alors que mes champs de temps (start_time, end_time) ne le sont pas? Est-ce parce que les simples adaptateurs de curseurs ne peuvent traiter que les ints et les chaînes et que mes variables temporelles proviennent des horodatages sql de la base de données?

Répondre

1

Désolé les gars, ne perdez pas votre temps à ce sujet.

le problème était une faute de frappe .. j'ai parlé android_id dans mon fichier xml quand il aurait dû être android: id

merci quand même

Kev

+0

Ne pas oublier d'accepter votre réponse ! – Josh

+0

@josh, Vous ne pouvez pas accepter votre propre réponse tout de suite, quand j'ai essayé de le faire plus tôt, il m'a dit que je devais attendre 22 heures avant de pouvoir accepter ma propre réponse –