Answer the question
In order to leave comments, you need to log in
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).
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
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 questionAsk a Question
731 491 924 answers to any question