1

我需要在列表视图中显示一些关于数字的数据。我从一个 sqlite 的数据库中获取这些数据。

我使用一个简单的光标适配器来填充列表视图。问题是 >= 到一百万的数字以指数格式存储。因此,例如,如果我插入一个像 1000 000 这样的数字,那么它将存储为 1+06E。问题是我需要将其显示为 1 000 000。但我无法更改光标或 simplecursoraapter 内的格式。

我填写列表视图的代码是:

Cursor c = admin.obtenerCursorGastosVarFecha(fechaSelUs);

      // The desired columns to be bound
      String[] columnas = new String[] {"_id", "Descripcion", "Costo", "Fecha_Creado"};

      // the XML defined views which the data will be bound to
      int[] views = new int[] {R.id.IdGstVar, R.id.DescGstVar, R.id.CostoGstVar, R.id.FechaGstVar };

      // create the adapter using the cursor pointing to the desired data 
      //as well as the layout information
      dataAdapter = new SimpleCursorAdapter(this, R.layout.lista_gastos_variables, c, columnas, views, 0);

我以字符串的形式来到这里,但高于或等于一百万的数字以指数形式出现

我试过这段代码,但它根本不起作用。

它只是修改低于一千万的值,并且它会舍入或更改值,因此如果插入例如 8 888 888 它会显示 8 888 890。

我需要以自然数显示存储在数据库中的所有数字。

此外,如果有一种方法可以将带有数字的行插入数据库而不将它们更改为指数格式,它是如何完成的?非常感谢您的帮助!

dataAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
            @Override
            public boolean setViewValue(View view, Cursor cursor, int column) {

                if( column == 2 ){ // let's suppose that the column 0 is the date
                    TextView tv = (TextView) view;

                    // here you use SimpleDateFormat to bla blah blah
                    tv.setText(""+Double.parseDouble(cursor.getString(cursor.getColumnIndex("Costo"))));
                    return true;
                }




                return false;
            }
        });
4

1 回答 1

0

由于您将数据类型用作 real ,并将其作为实数存储到 db 中。在存储到 SqliteDB 时,它会将其转换为指数格式。当您尝试从数据库中读取它时,它会将转换后的指数格式转换为字符串。您只需将数据类型更改为varcharfor costo。它会解决你的问题。

于 2013-07-25T05:21:51.410 回答