Note that there are some explanatory texts on larger screens.

plurals
  1. POpopulating multiple data into android listview
    primarykey
    data
    text
    <p>I am trying to learn populating data from the server to Listview.</p> <p>I am new to android</p> <p><strong>MainActivity.java</strong></p> <pre><code>public class MainActivity extends Activity { // url to make request private static String url = "http://URL:7002/"; private static String url1 = "http://URL:7002/XXX"; //private HashMap&lt;Integer, String&gt; TimeMap = new HashMap&lt;Integer, String&gt;(); List&lt;Item&gt; yourData = new ArrayList&lt;Item&gt;(); List&lt;Item&gt; yourData1 = new ArrayList&lt;Item&gt;(); ProgressDialog progressDialog; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //Instantiating ProgressDialog with onCreate method progressDialog=new ProgressDialog(MainActivity.this); new ParsingAsync().execute(); } private class ParsingAsync extends AsyncTask&lt;Void, Void, Void&gt; { @Override protected void onPreExecute() { // TODO Auto-generated method stub super.onPreExecute(); progressDialog=ProgressDialog.show(MainActivity.this, "", "Please Wait", true, false); } @Override protected Void doInBackground(Void... params) { // TODO Auto-generated method stub // Creating JSON Parser instance JSONObjParser jParser = new JSONObjParser(); // getting JSON string from URL JSONArray json = jParser.getJSONFromUrl(url); // getting JSON string from URL JSONArray json1 = jParser.getJSONFromUrl(url1); try { for (int i = 0; i &lt; json1.length(); i++) { JSONObject c = json1.getJSONObject(i); // Storing each json item in variable int id = c.getInt("_id"); String TIME = c.getString("RestaurantTime"); yourData1.add(new Item(TIME)); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { for (int i = 0; i &lt; json.length(); i++) { JSONObject c = json.getJSONObject(i); // Storing each json item in variable String NAME=c.getString("restaurantNAME"); yourData.add(new Item(NAME)); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } @Override protected void onPostExecute(Void result) { // TODO Auto-generated method stub super.onPostExecute(result); progressDialog.dismiss(); //TextView timedisplay=(TextView) findViewById(R.id.RestaurantTimeID); ListView yourListView = (ListView) findViewById(R.id.listViewID); ListAdapter customAdapter = new ListAdapter(MainActivity.this, R.layout.itemlistrow, yourData); yourListView.setAdapter(customAdapter); // remaining code </code></pre> <p><strong>ListAdapter.java</strong></p> <pre><code>public class ListAdapter extends ArrayAdapter&lt;Item&gt; { private List&lt;Item&gt; items; public ListAdapter(Context context, int resource, List&lt;Item&gt; items) { super(context, resource, items); this.items = items; } @Override public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; TextView tt = null; TextView time=null; if (v == null) { LayoutInflater vi; vi = LayoutInflater.from(getContext()); v = vi.inflate(R.layout.itemlistrow, null); tt = (TextView) v.findViewById(R.id.RestaurantNameID); time = (TextView) v.findViewById(R.id.RestaurantTimeID); } Item p = items.get(position); if (p != null) { if (tt != null) { tt.setText(""+p.getName()); } if (time != null) { time.setText(""+p.getTime()); } } return v; } } </code></pre> <p><strong>Item.java</strong></p> <pre><code>public class Item{ private String Name; private String Time; public Item(String name){ this.Name = name; } public String getName(){ return Name; } public void Time(String time){ this.Time = time; } public String getTime(){ return Time; } } </code></pre> <ul> <li>How can i resolve this</li> <li>I have posted required classes above</li> <li>Using List for populating the data is i am looking at</li> </ul> <p>Any ideas,</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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