Reputation: 57
I would like to display my list of orders depending on the tables. In my spinner i have the numbers of the tables, now if I select table n 1 I would like to see in the list view all the orders made by the first table.
spin.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Intent showDetails = new Intent(getApplicationContext(), Comm.class);
showDetails.putExtra("N_TABLE", MenuClicked.getInt("N_TABLE"));
startActivity(showDetails);
String items = spin.getSelectedItem().toString();
Log.i("Selected item : ", items);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
This is just the part of the code. I know it is incorrect but I don't know what to put there in order for it to work.
I've tried changing it into:
spin.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
/*Intent intent = new Intent(getApplicationContext(),SousMenu.class);
startActivity(intent);*/
try {
JSONObject MenuClicked = jsonArray.getJSONObject(position);
Intent showDetails = new Intent(getApplicationContext(), Comm.class);
showDetails.putExtra("N_TABLE", MenuClicked.getInt("N_TABLE"));
startActivity(showDetails);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
Upvotes: 2
Views: 1277
Reputation: 151
Please forgive me if this isn't what you wanted. Trying to help but as I'm new to stack overflow I can't make comments yet.
From what I understand of your question you have a spinner with a list of tables. When you select a value from the spinner a query is ran on an online database and returned to you all the orders for said table. If my understanding is correct then I recommend you return a json object, loop through said object adding the orders to the listview with the mAdapter.add(myitem) as Nick wrote.
Upvotes: 0
Reputation: 21753
I don't think you need an intent.
In your activity keep a reference to your ListView's Adapter as a member variable - I'll call it mAdapter
.
In your adapter make sure there is an add(myItem)
method. In onItemSelected
call mAdapter.add(myItem)
.
The add() method in the adapter should add the new item into the internally stored list. it should then call notifyDataSetChanged()
so that the ListView
is updated.
Upvotes: 1