-2

In my Android Application, I want to change this method to static, however when I add 'static' to the method signature, my IDE tells me that a non-static context cannot be referenced from a static context (on the findViewByID(R.id.listView).

public void populateListView(ArrayList<Income> incomeArray) {
    ArrayList<Income> array = incomeArray;
    ArrayAdapter<Income> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, array);
    ListView listView = (ListView) findViewById(R.id.listView);
    listView.setAdapter(adapter);

How could I make this method static?

shkschneider
  • 17,185
  • 13
  • 56
  • 110
Matthew Levene
  • 67
  • 1
  • 10

1 Answers1

1

make them global and Initialize your values out of your function or passing them as an argument, you are using this.findViewById(R.id.listView) which is not a static function.

Arash GM
  • 10,166
  • 6
  • 57
  • 74