-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,833
  • 13
  • 59
  • 112

1 Answers1

0

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,316
  • 6
  • 58
  • 76