Note that there are some explanatory texts on larger screens.

plurals
  1. POFilter a listview instead of re-querying the database with more specific criteria
    primarykey
    data
    text
    <p>The subject doesn't seem to have been discussed a lot in details so I am gonna explain my situation as well as possible to make it clear and hopefully get some explanations. </p> <p>My app allows the user to get information about places : there are different menus with different buttons corresponding to categories of places (food/ fastfood, restaurants, ... OR stores/shops, .... and so on). The user clicks on the button of his choice, it will send a request to my database and display a listview with the results. This way :<br> <img src="https://i.stack.imgur.com/JflHL.jpg" alt="enter image description here"> It is one example, but there are 16 possibilities like this, and everytime it's opening the same activity (ResultListViewActivity) but displaying different content. </p> <p>I want the user to be able to make more accurate research, so there is a filter mode as you can see on picture 3. The window appearing allows to choose some more criteria. What I planned so far was to fill some variable everytime the user clicks on something. Like if he chooses to pay with a credit card, VALUECARD = X, if budget = something then VALUEBUDGET = Y and so on and when you click on OK it sends all the value package to a method querying the database and open a new listview with the results. It would definitely works, and I know how to do. But I also think it's not really a good way to query the database every time, why not searching directly in the list view ? </p> <p>I know how to query the database, as my method is working to display listview (see picture 2), but I have no idea how to query a listview, especially when some columns from the database I would use in my filering are not imported in my cursor and then in my listview. I guess I would first have to import every column I might need for filtering.<br> Here is the code of my method displaying the listview so you see how my cursor is filled and my adapter is made : </p> <pre><code>private void displayListView() { // getExtra Bundle bundle = getIntent().getExtras(); String title = bundle.getString("title", "Choose here :"); String inInterval = bundle.getString("inInterval"); Log.d(TAG, "inInterval = " + inInterval); poititle.setText(title); // put the results of the method in a cursor Cursor c = dbHelper.findPoiInTable(inInterval); String[] columns = new String[] { DatabaseAdapter.COL_NAME, DatabaseAdapter.COL_STREET, DatabaseAdapter.COL_WEBSITE, DatabaseAdapter.COL_TELEPHONE, DatabaseAdapter.COL_REMARKS, DatabaseAdapter.COL_PRICE }; int[] to = new int[] { R.id.name, R.id.street, R.id.website, R.id.telephone, R.id.remarks, R.id.price }; cursorAdapter = new SimpleCursorAdapter(this, R.layout.poi_info, c, columns, to, 0); ListView listView = (ListView) findViewById(R.id.poilistview); // Assign adapter to ListView listView.setAdapter(cursorAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { // Comportement des éléments de la listview @Override public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { Intent i = new Intent(getApplicationContext(), POIActivity.class); String name = ((TextView) view.findViewById(R.id.name)) .getText().toString(); String website = ((TextView) view.findViewById(R.id.website)) .getText().toString(); String telephone = ((TextView) view .findViewById(R.id.telephone)).getText().toString(); String remarks = ((TextView) view.findViewById(R.id.remarks)) .getText().toString(); String price = ((TextView) view.findViewById(R.id.price)) .getText().toString(); // i.putExtra(ID_EXTRA, name) ; i.putExtra(ID_NAME, name); i.putExtra(ID_WEBSITE, website); i.putExtra(ID_TELEPHONE, telephone); i.putExtra(ID_REMARKS, remarks); i.putExtra(ID_PRICE, price); startActivity(i); } }); } </code></pre> <p>In this particular case, how could I for example filter the "COL_PRICE" which is in my cursor ? To be more precise, in my filter menu, when the user sets the budget and we get a value, how to use this value in relation to the value from COL_PRICE and keep elements under the given value ?<br> Thanks for any information !</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload