5

I am trying to input data from a List<ParseObject> to a cursor. ParseObject documentation can be found here.

I found out that you can use MatrixCursor to do this, referring to helpful sites: http://developer.android.com/reference/android/database/MatrixCursor.html

How to insert extra elements into a SimpleCursorAdapter or Cursor for a Spinner?

How to create Cursor data without getting data from the DataBase in Android application?

My problem is, when I return the cursor from MyContentProvider.java, and I try to do a cursor.getFloat(), it returns a String and I cannot do DecimalFormat on it.

Question:

How do I put more than one kind of data type into the MatrixCursor using, addRow (Object[] columnValues)?

Method that uses Cursor data:

public void getData() { Cursor cursor = getContentResolver().query(URI, null, mParseId, null, null); DecimalFormat df = new DecimalFormat(); df.setMinimumFractionDigits(2); mTextview.setText(df.format( cursor.getFloat(cursor.getColumnIndexOrThrow("number")))); } 

MyContentProvider.java:

@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { ...... MatrixCursor mc = new MatrixCursor(new String[] { "_id", "title", "number" }); mc.addRow(new String[] { ParseObject.getString("id"), ParseObject.getString("title"), ParseObject.getString("number") }); return mc; } 

What I want to do in MyContentProvider.java:

@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { ...... MatrixCursor mc = new MatrixCursor(new String[] { "_id", "title", "number" }); mc.addRow(new String[] { ParseObject.getLong("id"), ParseObject.getString("title"), ParseObject.getDouble("number") }); return mc; } 
2
  • "and I try to do a ParseObject.getDouble(), it returns a String"- you sure about that? Commented Aug 21, 2013 at 22:05
  • a sorry, I meant to say cursor.getFloat() returns a String, will edit my question Commented Aug 22, 2013 at 21:08

1 Answer 1

0

I'm not sure that I understand your code samples, but I can answer on your main question

How do I put more than one kind of data type into the MatrixCursor using, addRow (Object[] columnValues)?

Change array type from String to Object:

mc.addRow(new Object[] {1, "text", 0.666}); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.