Created
July 2, 2016 09:50
-
-
Save Egorand/9bea288752d0a02df44d58d8289e1089 to your computer and use it in GitHub Desktop.
android-espresso-sorted-list-teams-activity-oncreate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
RecyclerView teamsRecyclerView = (RecyclerView) findViewById(android.R.id.list); | |
teamsRecyclerView.setLayoutManager(new LinearLayoutManager(this)); | |
TeamsAdapter teamsAdapter = new TeamsAdapter(LayoutInflater.from(this)); | |
teamsAdapter.setTeams(createTeams()); | |
teamsRecyclerView.setAdapter(teamsAdapter); | |
} | |
private List<Team> createTeams() { | |
List<Team> teams = new ArrayList<>(); | |
String[] teamNames = getResources().getStringArray(R.array.team_names); | |
TypedArray teamLogos = getResources().obtainTypedArray(R.array.team_logos); | |
for (int i = 0; i < teamNames.length; i++) { | |
Team team = new Team(teamNames[i], teamLogos.getResourceId(i, -1)); | |
teams.add(team); | |
} | |
teamLogos.recycle(); | |
Collections.sort(teams, Team.BY_NAME_ALPHABETICAL); | |
return teams; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment