So i was making this app which displays an arrayList of different poems I first request the poems from API then the Asynctask returns the poems in the form of Arraylist i wand to show 20 random poems from the list.
This is the Asynctask code
private class TitleAsynctask extends AsyncTask<URL,Void,List<view>> {
private ProgressDialog progressDialog;
@Override
public List<view> doInBackground(URL... urls){
URL url = Query_utils.createurl(POEM_TITLE);
String json = "";
Log.d(LOG_TAG,"this worked");
{
try {
json = Query_utils.makehttprequest(url);
Log.d(LOG_TAG, "make Httprequest works");
} catch (IOException e) {
}
}
List<view> title_view = Query_utils.extracttitlefromjson(json);
return title_view;
}
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
@Override
protected void onPostExecute(List<view> data) {
madapter.clear();
if (data != null && !data.isEmpty()){
madapter.addAll(data);
}
}
}
and the onCreate code is
TitleAsynctask task = new TitleAsynctask();
URL url = Query_utils.createurl(POEM_TITLE);
task.execute(url);
ArrayList<view > arr = new ArrayList<view>();
final ListView poem_Title_list = (ListView) findViewById(R.id.list_item);
madapter = new title_adapter(this ,arr);
poem_Title_list.setAdapter(madapter);