I
I
Ismail2017-05-01 00:21:39
Android
Ismail, 2017-05-01 00:21:39

How to run AsyncTask with SimpleAdapter in Fragment?

Hello comrades (the teacher drove this word into mine, do not pay attention)))
In general, the essence of the problem is as follows, in the application I decided to add a ViewPager and since it works with fragments, it was necessary to transfer the listView from the activity to the fragment (the activity contained leaves with news).
170b6b1428fb4701a2433e186923bda0.png
I uploaded the news to AsyncTask with SimpleAdapter, but now how to do this in a fragment, it’s impossible to assign values ​​to SimpleAdapter (error on the screen) )
How to implement all this help Noob

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ismail, 2017-05-04
@Scripatch

In general, I solved this problem in the following way

@Override
    public void onAttach(final Context context) {
        super.onAttach ( context );

        new MainFragment.mDgu (context).execute();


    }

class mDgu extends AsyncTask<String, String, String> {
        ArrayList<Map<String, Object>> mData;
        private Context mActivity;

        public mDgu(Context context){
            mActivity = context;
        }

        @Override
        protected String doInBackground(String... arg) {
            ...
                }

            } catch (IOException e) {
                e.printStackTrace ();
            }
            return null;
        }

        @Override
        protected void onPostExecute(String result) {
            mmSimpleAdapter = new SimpleAdapter ( mActivity, mData, R.layout.item_news, from, to );
            mSimpleDgu.setAdapter ( mmSimpleAdapter );
        }
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question