Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is the code for those who will face with the same problem as i did.Thanks to Taynã Bonaldo i made it through problems. </p> <pre><code>public class MainActivity extends ListActivity { private static final String URL = "http://192.168.1.103/php-android/testphp.php"; private static final String TAG_DATA = "data"; private static final String TAG_ID = "name"; private static final String TAG_DATE = "date"; public PullToRefreshListView listView; public JSONArray data = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.pull_to_refresh); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder() .detectAll().penaltyLog().build(); StrictMode.setThreadPolicy(policy); listView = (PullToRefreshListView) getListView(); listView.scrollTo(0, 60); // Set a listener to be invoked when the list should be refreshed. ((PullToRefreshListView) getListView()).setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh() { // Do work to refresh the list here. new GetDataTask().execute(); } }); GetArrayData(); } private void GetArrayData() { // TODO Auto-generated method stub// Hashmap for listView ArrayList&lt;HashMap&lt;String, String&gt;&gt; dataList = new ArrayList&lt;HashMap&lt;String,String&gt;&gt;(); // creating JSON Parser instance JSONParser jParser = new JSONParser(); // getting JSON string from URL JSONObject json = jParser.getJSONFromUrl(URL); try { // Getting Array data data = json.getJSONArray(TAG_DATA); for(int i = 0; i &lt; data.length(); i++){ JSONObject c = data.getJSONObject(i); // Storing each jason item in variable String name = c.getString(TAG_ID); String date = c.getString(TAG_DATE); // creating new HashMap HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); // Adding each child node to HASMap key =&gt; value map.put(TAG_ID, name); map.put(TAG_DATE, date); // adding HashList to Array list dataList.add(map); } }catch (JSONException e) { e.printStackTrace(); } // Updating parsed JASON data in to ListView ListAdapter adapter = new SimpleAdapter(this, dataList, R.layout.list_item, new String[]{TAG_ID, TAG_DATE}, new int[]{ R.id.name, R.id.date}); // Set view to listView listView.setAdapter(adapter); } private class GetDataTask extends AsyncTask&lt;Void, Void, String[]&gt;{ @Override protected String[] doInBackground(Void... params) { // TODO Auto-generated method stub try { Thread.sleep(2000); } catch (InterruptedException e) { ; } return null; } @Override protected void onPostExecute(String[] result) { // listView.scrollTo(0,0); GetArrayData(); // Call onRefreshComplete when the list has been refreshed. ((PullToRefreshListView) getListView()).onRefreshComplete(); super.onPostExecute(result); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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