Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 返回并绑定到列表视图的双精度项被截断_Java_Android_Database_Sqlite_Double Precision - Fatal编程技术网

Java 返回并绑定到列表视图的双精度项被截断

Java 返回并绑定到列表视图的双精度项被截断,java,android,database,sqlite,double-precision,Java,Android,Database,Sqlite,Double Precision,我正在为我的Android应用程序查询sqlite数据库 然后,我使用一个简单的游标适配器将数据绑定到列表视图 从数据库中调用了两个double,在列表视图中仅显示为6位数 示例:43.6234和-116.203 在数据库中(我转储了它),这些数字有更多的数字 出了什么问题? 下面是列表视图的行XML <?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:id="@+id/relativeLayou

我正在为我的Android应用程序查询sqlite数据库

然后,我使用一个简单的游标适配器将数据绑定到列表视图

从数据库中调用了两个double,在列表视图中仅显示为6位数

示例:
43.6234
-116.203

在数据库中(我转储了它),这些数字有更多的数字

出了什么问题? 下面是列表视图的行XML

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

查看此处后:krysanify.wordpress.com/2010/11/24/…我在SimpleCorsorAdapter中发现了一个缺陷,该缺陷仅假设字段将是失去所需精度的字符串

我扩展了SimpleCursorAdapter,在我想要的行上使用Double,这里是类

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");
                    }
                }
            }
        }
    }
}
带有LongAdapter的公共类扩展了SimpleCorsAdapter{ 私有int[]mFrom; 私人国际[]mTo; /** *SimpleCursorAdapter,它还基于行检查双值,以便它们不会被截断 *@param context传递此消息 *@param布局行文件 *@param c光标 *@param来自光标上的collums *@param到列表中的行 */ 公共WithLongAdapter(上下文上下文、int布局、游标c、, 字符串[]从,整数[]到){ super(上下文、布局、c、from、to); mTo=to;//必须创建自己的to和from,因为它们在SimpleCursorAdapter中受保护 如果(c!=null){ int i; int count=from.length; if(mFrom==null | | mFrom.length!=count){ mFrom=新整数[计数]; } 对于(i=0;i创建数据库时,此表的create query的语法是什么?您可能已经为这些设置了更精确的保持器。
创建扫描表(_idinteger主键自动递增,“+”ssid text,“+”essid text,“+”纬度双精度,“+”精度浮点,“+”经度双精度,“+”rssi integer);”就像我说的,我检查了表的内容,数字是正确的。那么从数据库中获取这些数据呢?您是否在低精度数据类型中的某个位置分配了它们?否,我按原样查询它们,并将光标交给
SimpleCursorAdapter
我曾尝试在断点期间查看光标变量,以查看它在交给列表之前是否是低精度的,但我在光标中找不到行数据(我确信它在那里)。这是一个很大的物体