Note that there are some explanatory texts on larger screens.

plurals
  1. POproblem viewing the items of more shoppinglist in android
    text
    copied!<p>Hey everyone!<br/> I have a problem in my android app. I am trying to do a shopping list app. I tried to do 2 shopping list in my app,each of them with its items. When I what to see the items of an list I use a SimpleCursorAdapter.The problem is that if I want to see the items of second list I see its items ,and the first one also. What should I do? All the titles of lists are stored in a table and all the items are stored in an other table. Here is my class All ideas are welcomed.<br/> Thank you.</p> <p>My code:</p> <pre><code>public class Produse extends Activity{ TextView selection; String titlelist; String id; private ProductDbAdapter prod; private ListDbAdapter db; private SimpleCursorAdapter adapter; private ListView lv; private static final int MENU_ADD = Menu.FIRST; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.produse); selection=(TextView)findViewById(R.id.text); lv=(ListView)findViewById(R.id.listprod); Bundle bundle = getIntent().getExtras(); titlelist = bundle.getString("param1"); id=bundle.getString("param2"); selection.setText(titlelist); db=new ListDbAdapter(this); db.open(); prod=new ProductDbAdapter(this); prod.open(); populate(); prod.close(); db.close(); } public boolean onCreateOptionsMenu(Menu menu) { menu.add(0, MENU_ADD, 0, "Add Item"); return true; } public boolean onOptionsItemSelected (MenuItem item) { switch (item.getItemId()) { case MENU_ADD: additem(); return true; } return false; } public void additem() { Intent j= new Intent(Produse.this, List2.class); j.putExtra("param2", id); startActivity(j); } private void populate(){ Cursor c=prod.fetchAll(); startManagingCursor(c); if (c.moveToFirst()){ do{ if (id.toString().equals(c.getString(1))) adapter=new SimpleCursorAdapter(this,R.layout.listproduct,c, new String[] {ProductDbAdapter.KEY_ITEM,ProductDbAdapter.KEY_QUANTITY,ProductDbAdapter.KEY_UNITS}, new int[] {R.id.prod1,R.id.prod2,R.id.prod3}); }while (c.moveToNext()); lv.setAdapter(adapter); } } } </code></pre>
 

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