Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Write this in your oncreate method , Here rssFeed is the url you are passing.</p> <pre><code>MyTask().execute(rssFeed); </code></pre> <p>and make a new class called MyTask which extends asynctask.</p> <pre><code>class MyTask extends AsyncTask&lt;String, Void, String&gt; { ProgressDialog pDialog; @Override protected void onPreExecute() { super.onPreExecute(); pDialog = new ProgressDialog(MainActivity.this); pDialog.setMessage("Loading..."); pDialog.setCancelable(false); pDialog.show(); } @Override protected String doInBackground(String... params) { return Utils.getJSONString(params[0]); } @Override protected void onPostExecute(String result) { super.onPostExecute(result); if (null != pDialog &amp;&amp; pDialog.isShowing()) { pDialog.dismiss(); } if (null == result || result.length() == 0) { showToast("No data found from web!!!"); MainActivity.this.finish(); } else { try { JSONArray jArray = new JSONArray(result); JSONObject json_data=null; for(int i=0;i&lt;jArray.length();i++) { json_data = jArray.getJSONObject(i); b.add(json_data.getString("Organization")); } setListAdapter(new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1,b)); } catch(JSONException e1){ Toast.makeText(getBaseContext(),e1.toString() ,Toast.LENGTH_LONG).show(); } catch (ParseException e1) { Toast.makeText(getBaseContext(),e1.toString() ,Toast.LENGTH_LONG).show(); } </code></pre> <p>}</p> <p>and make a new class called Utils and do the Http stuff over there.</p> <pre><code>public class Utils { public static String getJSONString(String url) { String jsonString = null; HttpURLConnection linkConnection = null; try { URL linkurl = new URL(url); linkConnection = (HttpURLConnection) linkurl.openConnection(); int responseCode = linkConnection.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK) { InputStream linkinStream = linkConnection.getInputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); int j = 0; while ((j = linkinStream.read()) != -1) { baos.write(j); } byte[] data = baos.toByteArray(); jsonString = new String(data); } } catch (Exception e) { e.printStackTrace(); } finally { if (linkConnection != null) { linkConnection.disconnect(); } } return jsonString; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload