How to return ArrayList from AsyncTask to another class?

后端 未结 7 600
被撕碎了的回忆
被撕碎了的回忆 2021-01-21 20:01

i want to get Ftp folders list from server using AsyncTask and return folders names ArrayList to main class and update spinner adapter.

In main class i got spinner with

7条回答
  •  盖世英雄少女心
    2021-01-21 20:14

    In your main, where you are calling your AsyncTask, overwrite the onPostExecute method and put your adapter stuff in there. It gets called on the UI Thread, so it's save.

    So where you are calling the AsyncTask, do

    new FTPTeacher() {
    
     public void onPostExecute(List list) {
    
         createfile_spinTeacher = (Spinner) findViewById(R.id.createfile_spinTeacher);   
         final ArrayAdapter dataAdapterTeacher = new ArrayAdapter(this, android.R.layout.simple_spinner_item,list);
         dataAdapterTeacher.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
         createfile_spinTeacher.setAdapter(dataAdapterTeacher);
    
     }
    
    }.execute();
    

提交回复
热议问题