1

I am using JSoup to get a list of NFL Teams from a specific year and load them into a spinner. I am porting a program I made to Android to get some more practice in since I am still a little bit new to Android. My problem has to do with spinners. In my PC program, I had the line: MainWindow.homeTeam.setModel(new DefaultComboBoxModel(teams.toArray())); and in my Android app, I have this:

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
            teams.toArray(), android.R.layout.simple_spinner_item);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            MainWindow.awayTeam.setAdapter(adapter);

I am getting an error with "this" saying "cannot use this in static context". I have been going at this for a while with no prevail. Here is my method:

    public static void setTeamComboBox(int comboBoxID, String year) throws IOException {

    List<String> teams = new ArrayList<String>();
    String AllGamesURL = "http://www.nfl.com/standings?category=league&season=" + year + "-REG";
    Document AllGames = Jsoup.connect(AllGamesURL).get();
    Elements AllGamesTeams = AllGames.select("table.data-table1 tr.tbdy1");

    int i = 0;
    for (Element teamName : AllGamesTeams) {
        if(teamName.select("td[align] > a[href]").text().trim().equals("")) {
            teams.add(teamName.select("td[align]").text().trim());
        } else {
            teams.add(teamName.select("td[align] > a[href]").text().trim());
        }
    }

    Collections.sort(teams);

    if(comboBoxID == 1) {
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
        teams.toArray(), android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        MainWindow.awayTeam.setAdapter(adapter);
    } else {
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
        teams.toArray(), android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        MainWindow.homeTeam.setAdapter(adapter);
    }
}
ollo
  • 24,797
  • 14
  • 106
  • 155
  • 1
    Please see [Cannot use 'this' in static context](http://stackoverflow.com/questions/17233367/cannot-use-this-in-static-context) which help you in understanding why `cannot use this in static context` message occur.Thanks – ρяσѕρєя K Feb 11 '14 at 04:12

0 Answers0