lundi 27 avril 2015

display data from database in text view - android

i am trying to display data in different text view the problems is that when is call returnIngrediant(id) and assign it to the text view it only display ecapp_col_ingredant only

and is it possible to make every piece of data retrieved form the DB in new line

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.recipe);
    name = (TextView) findViewById(R.id.name);
    Ingredant = (TextView) findViewById(R.id.Ingredant);
    discretion = (TextView) findViewById(R.id.discretion);
    Bundle bundle = getIntent().getExtras();
    id = bundle.getString("name");
    Log.e("name ", id);

    db = new dbtry(getBaseContext());
    db = new dbtry(recipeActivity.this);

    db.open();

    db.read();


    Cursor d = db.returnRecipe(id);


    if (d.moveToFirst()) {
        Log.e("if ", "yah!");

        do {
            Log.e("do ", "yah!");

            name.setText(d.getString(0));
            discretion.setText(d.getString(1));

            Cursor d2 = db.returnIngrediant(id);
            String ingrediant = "";
            if (d2.moveToFirst()) {
                do {
                    ingrediant += d2.getString(0) +",";

                    Ingredant.setText(ingrediant);

                } while (d2.moveToNext());

            }


            Log.e("the while ", "happy");

        } while (d.moveToNext());
        Log.e("the app search ", "happy");

    }

}

my query

public Cursor returnRecipe(String rname)

{
    //sqldb = dbh.getReadableDatabase();
    //Cursor query;
    //return db2.query(TABLE_NAME1, null, ecapp_col_id + "=" + id, null, null, null, null);

    Cursor query = db2.rawQuery("select " + ecapp_col_name + ", " + ecapp_col_description + " from " + TABLE_NAME1 + " where " + ecapp_col_name + "=? ", new String[]{rname});
    Log.e("get all data:", "query");
    return query;


}

public Cursor returnIngrediant(String sname)

{


    Cursor query = db2.rawQuery("select "+ecapp_col_ingredant+ ","+ ecapp_col_Optional_ingredant + " from " + TABLE_NAME2+ " where " +ecapp_col_name + "= ?", new String[]{sname});
    Log.e("returnIngrediant:", ecapp_col_Optional_ingredant);
    return query;


}

Aucun commentaire:

Enregistrer un commentaire