Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the relationship between ListView and using ArrayAdapter to show arraylist?
    text
    copied!<p>I have been for the past several hours trying to do something that I think should be trivial. I keep reading answers on stackoverflow but its not jiving with me. people show examples of <code>ArrayAdapters</code> accepting string <code>ArrayLists</code> on stackoverflow. This is just not working for me. </p> <p><a href="https://stackoverflow.com/questions/5070830/populating-a-listview-using-arraylist">Populating a ListView using an ArrayList?</a></p> <p>I am trying to understand what is going on here. If I am dealing with an arraylist of type String that means that the only thing I can bind the data to is a textview and certainly not a listview unless I create my own custom link adapter class? This just seems like I am missing some information. I would thing this problem would be so common a solution would have been made. My code is below and I am getting the "<code>E/ArrayAdapter(5106): You must supply a resource ID for a TextView</code>" error. </p> <pre><code>public class Favorites extends Activity{ UserFunctions userFunctions = new UserFunctions(); ArrayAdapter&lt;String&gt; arrayAdapter1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.favoritespage); arrayAdapter1 = new ArrayAdapter&lt;String&gt;(Favorites.this,android.R.layout.activity_list_item); new DownloadDataTask().execute(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_main_screen, menu); return true; } private class DownloadDataTask extends AsyncTask&lt;JSONArray, JSONArray, ArrayList&lt;String&gt; &gt; { @Override protected ArrayList&lt;String&gt; doInBackground(JSONArray... params) { JSONArray json = userFunctions.ziplistrequest("39", "-74", "50"); ArrayList&lt;String&gt; zipcodes = new ArrayList&lt;String&gt;(); for(int i=0; i &lt; json.length() ; i++) { JSONObject jarray = null; try { jarray = json.getJSONObject(i); String zip = jarray.getString("ZIPCODE"); zipcodes.add(zip); arrayAdapter1.add(zip); Log.d(zip,"Output"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return zipcodes; } protected void onPostExecute(ArrayList&lt;String&gt; result){ ListView listView = (ListView) findViewById(R.id.list); arrayAdapter1.addAll(result); listView.setAdapter(arrayAdapter1); } } </code></pre> <p>}</p>
 

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