2011-04-16 2 views
1

Je recherche ma base de données sqlite pour mon application Android. Puis, j'utilise un adaptateur de curseur simple pour lier les données à une vue de liste.Les doublons retournés et liés à la vue liste sont tronqués

Deux doubles sont appelés à partir de la base de données et sur la liste, seuls les six chiffres sont affichés.

Exemple: 43.6234 et -116.203

dans la base de données (je jetai il) ces chiffres ont beaucoup plus de chiffres.

Qu'est-ce qui n'a pas fonctionné? Voici mon XML de ligne pour la vue de la liste

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout android:id="@+id/relativeLayout2" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> 
     <TextView android:text="@string/ssid" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/row_db_ssid" android:textSize="16dip"></TextView> 
     <TextView android:layout_height="wrap_content" android:layout_below="@+id/row_db_bssid" android:textSize="12dip" android:text="@string/lati" android:layout_width="wrap_content" android:id="@+id/row_db_latitude"></TextView> 
     <TextView android:text="@string/bssid" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/row_db_bssid" android:layout_below="@+id/row_db_ssid" android:textSize="14dip"></TextView> 
     <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:text="@string/rssi" android:textSize="16dip" android:id="@+id/row_db_rssi"></TextView> 
     <TextView android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_below="@+id/row_db_bssid" android:textSize="12dip" android:text="@string/longi" android:layout_width="wrap_content" android:id="@+id/row_db_longitude"></TextView> 
    </RelativeLayout> 
+0

lorsque vous avez créé la base de données quelle était la syntaxe de requête pour créer cette table? peut être possible que vous avez donné un support plus précis pour ceux-ci. – Ravin

+0

' "create table numérisée (nombre entier _id autoincrement clé primaire" \t \t \t + "texte ssid" \t \t \t + "texte ESSID" \t \t \t + "de latitude double," \t \t \t +" + "longitude double", + "rssi entier"; ";' –

+0

Comme je l'ai dit cependant, j'ai vérifié le contenu de la table et les chiffres étaient corrects. –

Répondre

0

Après avoir regardé ici: krysanify.wordpress.com/2010/11/24/... j'ai trouvé une faille dans le SimpleCursorAdapter qui suppose que les champs seront cordes perdre la précision voulue

J'ai étendu le SimpleCursorAdapter pour utiliser Double sur les lignes que je voulais ici est la classe.

public class WithLongAdapter extends SimpleCursorAdapter { 
    private int[] mFrom; 
    private int[] mTo; 
/** 
* SimpleCursorAdapter that also checks for Double values based on rows so they will not be truncated 
* @param context pass this 
* @param layout the row file 
* @param c the Cursors 
* @param from collums on cursor 
* @param to rows on list 
*/ 
    public WithLongAdapter(Context context, int layout, Cursor c, 
      String[] from, int[] to) { 
     super(context, layout, c, from, to); 
     mTo = to; //have to make my own to and from because they are protected in SimpleCursorAdapter 
     if (c != null) { 
      int i; 
      int count = from.length; 
      if (mFrom == null || mFrom.length != count) { 
       mFrom = new int[count]; 
      } 
      for (i = 0; i < count; i++) { 
       mFrom[i] = c.getColumnIndexOrThrow(from[i]); 
      } 
     } else { 
      mFrom = null; 
     } 
    } 

    @Override 
    public void bindView(View view, Context context, Cursor cursor) { 
     final ViewBinder binder = getViewBinder(); 
     final int count = mTo.length; 
     final int[] from = mFrom; 
     final int[] to = mTo; 

     for (int i = 0; i < count; i++) { 
      final View v = view.findViewById(to[i]); 
      if (v != null) { 
       boolean bound = false; 
       if (binder != null) { 
        bound = binder.setViewValue(v, cursor, from[i]); 
       } 

       if (!bound) { 
        String text = cursor.getString(from[i]); 
        if (text == null) { 
         text = ""; 
        } else if (R.id.row_db_latitude == v.getId()) { //added rows, if they are the ones I want get value of doulbe 
         text = String.valueOf(cursor.getDouble(from[i])); 
        } 
        else if (R.id.row_db_longitude == v.getId()) { //added row 
         text = String.valueOf(cursor.getDouble(from[i])); 
        } 
        if (v instanceof TextView) { 
         setViewText((TextView) v, text); 
        } else if (v instanceof ImageView) { 
         setViewImage((ImageView) v, text); 
        } else { 
         throw new IllegalStateException(
           v.getClass().getName() 
             + " is not a " 
             + " view that can be bounds by this SimpleCursorAdapter"); 
        } 
       } 
      } 
     } 
    } 
} 
Questions connexes