I have a fragment and in onCreateView I have an adapter and a listview:
mAdapter = new ArrayAdapter<String>(getActivity(),
R.layout.list_item,
R.id.list_item_textview,
new ArrayList<String>());
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
ListView listView = (ListView) rootView.findViewById(R.id.listeview);
listView.setAdapter(mAdapter)
I also have a separate AsyncTask class and on its onPostExecute method I want to add items to the mAdapter:
@Override
protected void onPostExecute(String[] result) {
if(result !=null){
mAdapter.clear();
for(String mString: result){
mAdapter.add(mString);
}
I execute the AsyncTask in Fragment's onStart method :
@Override
public void onStart() {
super.onStart();
FetchData fetchData = new FetchData();
fetchData.execute(location);
}
How can I use the Fragment's mAdapter on AsyncTask class to update its data and then notify the listView?