samedi 23 avril 2016

How to parse grid view item id to SQLite WHERE claus?

When a user click on an item I need to get the item id and send it to list view activity. But the list view is populated from a pre-populated SQLite db and items should retrive based on item id of grid view.

Example : If user click item 1 (Bank icon) on first activity , list view should retrieve data of bank names.

This is my gridview onItem click code.

       grid.setAdapter(new CustomAdapter(this));

    grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            Intent intent=new Intent(MainActivity.this,ContactView.class);
            intent.putExtra("catid", id);
            startActivity(intent);

        }

    });


}

This is my code to retrieve list items on DB Access class.

    public List<String> getQuotes() {
    List<String> list = new ArrayList<>();
    String value;
    Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        value = bundle.getString("catid");
        Cursor cursor = database.rawQuery("SELECT org_name FROM org_name WHERE category_id='value'", null);
        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            list.add(cursor.getString(0));
            cursor.moveToNext();
            cursor.close();
        }
    }

    return list;
}

Aucun commentaire:

Enregistrer un commentaire