Try this:
An Interface:
public interface ILoadDataListener {
public void onComplete(ArrayList<String> data);
}
Your Fragment:
public static class NewsFragment extends ListFragment implements ILoadDataListener {
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// URL to the JSON data
String strUrl = "http://wptrafficanalyzer.in/p/demo1/first.php/countries";
// Creating a new non-ui thread task to download json data
GetJSON downloadTask = new GetJSON(this); //
// Starting the download process
downloadTask.execute(strUrl);
}
@Override
public void onComplete(ArrayList<String> result) {
YourAdapter adapter = new YourAdapter(..., result);
yourListView.setAdapter(adapter);
}
}
Your AsyncTask
public class GetJSON extends AsyncTask<String, Integer, ArrayList<String>>{ // return an ArrayList of String
//.... Your declaration
private ILoadDataListener mListener;
public GetJSON(ILoadDataListener listener) {
this.mListener = listener;
}
@Override
public void onPostExecute(ArrayList<String> result) {
if (mListener != null) {
mListener.onComplete(result);
}
}
}
Your Adapter
Use ArrayList<String> values;
instead of String[] values;