branch | hedgeroid |
changeset 5542 | 141c12a23787 |
parent 5532 | 3d7ac2b3b703 |
child 5603 | 4e4a579a60af |
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/TeamSelectionActivity.java Thu Aug 11 14:56:31 2011 +0200 +++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/TeamSelectionActivity.java Thu Aug 11 14:59:14 2011 +0200 @@ -27,6 +27,8 @@ public class TeamSelectionActivity extends Activity{ + private static final int ACTIVITY_TEAMCREATION = 0; + private ImageButton addTeam, back; private ListView availableTeams, selectedTeams; private ArrayList<HashMap<String, ?>> availableTeamsList, selectedTeamsList; @@ -86,6 +88,35 @@ } }; + public void onActivityResult(int requestCode, int resultCode, Intent data){ + if(requestCode == ACTIVITY_TEAMCREATION){ + if(resultCode == Activity.RESULT_OK){ + updateListViews(); + } + }else{ + super.onActivityResult(requestCode, resultCode, data); + } + } + + private void updateListViews(){ + unregisterForContextMenu(availableTeams); + availableTeamsList = FrontendDataUtils.getTeams(this); + for(HashMap<String, ?> hashmap : selectedTeamsList){ + String name = (String)hashmap.get("txt"); + for(HashMap<String, ?> hash : availableTeamsList){ + if(name.equals((String)hash.get("txt"))){ + availableTeamsList.remove(hash); + } + } + } + SimpleAdapter adapter = new SimpleAdapter(this, availableTeamsList, R.layout.team_selection_entry, new String[]{"txt", "img"}, new int[]{R.id.txtName, R.id.imgDifficulty}); + availableTeams.setAdapter(adapter); + registerForContextMenu(availableTeams); + availableTeams.setOnItemClickListener(availableClicker); + + + } + private void setTeamColor(int position, int color){ View iv = ((RelativeLayout)selectedTeams.getChildAt(position)).findViewById(R.id.teamCount); setTeamColor(iv, color); @@ -142,8 +173,7 @@ private OnClickListener addTeamClicker = new OnClickListener(){ public void onClick(View v) { - startActivity(new Intent(TeamSelectionActivity.this, TeamCreatorActivity.class)); - + startActivityForResult(new Intent(TeamSelectionActivity.this, TeamCreatorActivity.class), ACTIVITY_TEAMCREATION); } }; @@ -192,7 +222,7 @@ Intent i = new Intent(TeamSelectionActivity.this, TeamCreatorActivity.class); Team t = (Team)availableTeamsList.get(position).get("team"); i.putExtra("team", t); - startActivity(i); + startActivityForResult(i, ACTIVITY_TEAMCREATION); return true; } return false;