0

Hi I am new to android so sorry if I made a stupid mistake.

After my async function is done I call for my updateList function. My string Array's are made globally with the value loading. In my update function I turn the arrayList to a string array. My string gets updated in the function when i try to log it but when I use the variable outside the function it is not working. Can u please help me?

String[] packages = {
  Loading...
}
String[] statusPackages = {
  Loading...
}


public void updateList(List < String > name, List < String > status) {

  this.packages = name.toArray(new String[name.size()]);

  statusPackages = status.toArray(new String[status.size()]);

  Log.d("NAME", "Is this working?" + Arrays.toString(packages));

  Log.d("PACKAGES", Arrays.toString(packages));

  customAdapter.notifyDataSetChanged();
}

This my onPostExcute

  protected void onPostExecute(String s) {
  super.onPostExecute(s);
  Log.d("onpost", s);

  MainActivity mainActivity = new MainActivity();

  Log.d("Packages:", Arrays.toString(mainActivity.packages));

  mainActivity.updateList(name_array, status_array);

  Toast.makeText(this.context, "Loading is Done",
    Toast.LENGTH_LONG).show();

}
Guru
  • 1,653
  • 1
  • 7
  • 14
  • https://stackoverflow.com/questions/4042434/converting-arrayliststring-to-string-in-java – ADM Apr 24 '18 at 18:14
  • And This `MainActivity mainActivity = new MainActivity()` is a disaster if its not a test case Never create Activity instance its handled by Android framework itself. – ADM Apr 24 '18 at 18:16
  • But how do I make an instance of my activity then? @ADM – Roel Voordendag Apr 24 '18 at 19:14

0 Answers0