M.Dixon M.Dixon - 26 days ago 5
Android Question

data input not under column headers, i am trying to display the data in straight line columns...but its not working

hello am new at android development. am creating an app that has four columns. Student, age, number and class...but the data displayed under the columns is disorganized, how can i organize the data displayed in proper columns?

here is my code.
my database name = schooldatabase

String[] columns = new String[] { KEY_ROWID, KEY_STUDENT, KEY_AGE, KEY_ID_NUMBER, KEY_CLASS };
Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);

String result = "";
ArrayList<String> mArrayList = new ArrayList<String>();

int IROW = c.getColumnIndex(KEY_ROWID);
int ISTUDENT = c.getColumnIndex(KEY_STUDENT);
int IAGE = c.getColumnIndex(KEY_AGE);
int INUMBER = c.getColumnIndex(KEY_ID_NUMBER);
int ICLASS = c.getColumnIndex(KEY_CLASS);
// ////////////////////////////////////////////////////////
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {

// ////////////////////////////////////////////////////
result = result + c.getString(IROW) + " " + c.getString(ISTUDENT)
+ " " + " " + c.getString(IAGE) + " " + " "
+ c.getString(INUMBER) + " " + " " + c.getString(ICLASS)
+ "\n";
}

return result;

Answer

You can use rawQuery to query items as what you want column like:

ourDatabase.rawQuery("select <your columns order>" +  from + DATABASE_TABLE,null);

And I think whether the data is ordered depends on how you resolve this data,when you get all data you can handle these as you want order.