0

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 ArrayAdapters accepting string ArrayLists on stackoverflow. This is just not working for me.

Populating a ListView using an ArrayList?

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 "E/ArrayAdapter(5106): You must supply a resource ID for a TextView" error.

public class Favorites extends Activity{
UserFunctions userFunctions  = new UserFunctions();

ArrayAdapter<String> arrayAdapter1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.favoritespage);
    arrayAdapter1 = new ArrayAdapter<String>(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<JSONArray, JSONArray, ArrayList<String> > {


        @Override
        protected ArrayList<String> doInBackground(JSONArray... params) {
            JSONArray json = userFunctions.ziplistrequest("39", "-74", "50");
            ArrayList<String> zipcodes = new ArrayList<String>();
            for(int i=0; i < 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<String> result){
            ListView listView = (ListView) findViewById(R.id.list);
            arrayAdapter1.addAll(result);
            listView.setAdapter(arrayAdapter1);
        }
    }

}

Community
  • 1
  • 1
Mark
  • 911
  • 13
  • 30
  • I changed one thing on line 10 from "activity_list_item" to "simple_list_item_1" please let me know why this shows my list? I would like to understand so it does not catch me off guard in the future. – Mark Feb 04 '13 at 03:13

1 Answers1

0

Try using android.R.layout.simple_list_item1 instead of 'android.R.layout.activity_list_item`

pvn
  • 2,016
  • 19
  • 33
  • This does make it work which I put in my comment, but can you explain why? I want to understand that part of it. – Mark Feb 04 '13 at 21:59