samedi 27 février 2016

Retrieving data from SQLite

I'm trying to retrieve data from sqlite but I don't know what's wrong with my code

        private String user,position;
        private DatabaseHelper helper;
        private List<User> user_position;

this with inside onCreate

        user_position= helper.getUserPosition();
        user = String.valueOf(user_position.get(0).getUserName());
        position=String.valueOf(user_position.get(1).getUserPosition());
        TextView textView = (TextView) findViewById(R.id.user);
        textView.setText(user+"("+position+")");

and this is the database reader method

public List<User> getUserPosition() {

        List<User> oList = new ArrayList<User>();

        SQLiteDatabase db = getReadableDatabase();

        Cursor cursor = db.query(ORDER_TABLE, null, null, null, null, null,
                null);


            User user = new User();
            user.setUserName(cursor.getString(cursor
                    .getColumnIndex(ROW_USER)));
            user.setUserPosition(cursor.getString(cursor
                    .getColumnIndex(ROW_POSITION)));

            oList.add(user);

        if (cursor != null)
            cursor.close();

        if (db != null)
            db.close();

        return oList;

    }

Aucun commentaire:

Enregistrer un commentaire