lundi 4 janvier 2016

what causes the data to be displayed out of headers?

I can't figure out why data displayed in the database is disorganized/out of columns.
this is what I tried....

DataEntries.java

this is the activity with the textview, which displays the content from the database.

tv = (ListView) findViewById(R.id.tvsqlinfo);   
     StudentsDataBase db = new StudentsDataBase(this);      
    db.open();
    ArrayList<String> data = db.getData();

    db.close();     
//   tv.setText(data);
    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, data);
    tv.setAdapter(arrayAdapter);

and this is my StudentsDataBase.java

public long tableValues(String table, String values) {

    ContentValues vc = new ContentValues();
    vc.put(KEY_STUDENT, "");
    vc.put(KEY_AGE, "");
    vc.put(KEY_ID_NUMBER, "");
    vc.put(KEY_CLASS, "");

    return ourDatabase.insert(DATABASE_TABLE, null, vc);
   public ArrayList<String> getData() {

    String[] columns = new String[] { KEY_ROWID, KEY_STUDENT, KEY_AGE, 
            KEY_ID_NUMBER, KEY_CLASS };

    Cursor c = ourDatabase.rawQuery(
"select " + StringUtils.join(columns, ",") + " from" + DATABASE_TABLE, null);

String result =  "";
            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);
            ArrayList<String> string_array = new ArrayList<String>();   
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";

        string_array.add(result);
    }

    return string_array;

Aucun commentaire:

Enregistrer un commentaire