I have a button, “Load Team”, that, when clicked, I want to have a pop-up list of teams in the database. My question is threefold:
- Currently I have an AlertDialog that pops up when clicking the
button, but I cannot find how to populate the AlertDialog’s rows
from the database. (currently static list) - The second part of this question is that once I can populate the list, I want to display two returned columns concatenated together as follows: “Team Name (City)” or “team_ID – Team Name (City)”.
- Third, when they click the item, I want it to return the “team_id” column value
from the query instead of the list position or list string value.
Is this possible? Here is my code to populate the list with static values:
final CharSequence[] team_list = {"Team 1", "Team 2", "Team 3"};
final AlertDialog.Builder load_builder = new AlertDialog.Builder(this);
load_builder.setTitle("@string/pick_team");
load_builder.setItems(team_list, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Toast.makeText(getApplicationContext(), team_list[item], Toast.LENGTH_SHORT).show();
// I will sent team_id as parameter to query, to get all data for that team
}
});
I’ve searched extensively but can’t seem to find the right answer. If this is better as a pop-up ListView and/or with its own layout.xml, please let me know.
My problems have been resolved. I used a ListView inside of a Dialog. I used 2 ArrayLists, one storing strings for ListView, and the other storing corresponding ID (with matching array index).
team_list.xml:
ManageTeams.java: