vendredi 17 août 2018

how can I pass results of my checkboxes stored in an Arraylist to my DbHelper class to be used as a filter in my SELECT query method

I have done a bit of research on this request but yet to find a workable solution.I have a checkbox Listview and the checked results i stored in an array. I want to pass the results to my DB helper to be used in a databse filter when i run my SELECT query method. Find below my code. I know how to do it when passing from one Activity to another via Intent Extra, but i dont think Intent extra works when passing data to a class and not an Activity

The Source Activity/Class

public class LocationCategoryChkbx extends AppCompatActivity {

    ArrayList<String> selectedItems = new ArrayList<>();
    Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_location_category_chkbx);

        getSupportActionBar().setTitle("Your Foodometer:  Hungry ..");

        ListView chl = (ListView) findViewById(R.id.checkable_list);
        chl.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
        String[] items = {"Lekki", "Ikoyi", "Victoria Island", "Ikeja", "Ogudu", "Gbagada", "Ajah", "Chinese", "Indian", "Lebanese", "Grill", "Nigerian", "Dessert", "Thai"};
        ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.listview_chkbox, R.id.txt_lan, items);
        chl.setAdapter(adapter);
        chl.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String selectedItem = ((TextView) view).getText().toString();
                if (selectedItems.contains(selectedItem)) {
                    selectedItems.remove(selectedItem); //uncheck item
                } else
                    selectedItems.add(selectedItem);
            }
        });
    }

I want to use the results i.e. those boxes which were checked in the ArrayList in my getResturantList method as a filter in the query shown below;

public Cursor getResturantList(){
        SQLiteDatabase database=this.getWritableDatabase();
        Cursor resturantdata;
        resturantdata = database.rawQuery("SELECT * FROM " + TABLE_NAME,null);

        return resturantdata;
    }




Aucun commentaire:

Enregistrer un commentaire