Skip to content

Instantly share code, notes, and snippets.

@Egorand
Created July 2, 2016 09:50
Show Gist options
  • Save Egorand/9bea288752d0a02df44d58d8289e1089 to your computer and use it in GitHub Desktop.
Save Egorand/9bea288752d0a02df44d58d8289e1089 to your computer and use it in GitHub Desktop.
android-espresso-sorted-list-teams-activity-oncreate
@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