title: Populating a ListView with Objects from Parse.com Android
body: <p>I'm trying to fill a ListView with objects from my database at Parse.com, but I'm am having trouble because the ListView does not accept objects directly. I've tried making an array of strings by looping through my objects and casting them as strings but that failed.  I have also tried to call a .toString on the objects but no luck either.  </p>
  
  <p>My plan is to loop through all of the parse objects and then add them to the ListView. That ListView will then be used to allow the user to search through all of the objects from Parse.com. The objects from Parse.com should replace the listview_array[] data....ex replace "BudWeiser", "Dubra" etc....</p>
  
  <p>The loop I did create to retrieve the Objects names, prices, size did work, but I could not place it into the listView since I believe it was an object.</p>
  
  <p>Here's my code</p>
  
  <pre><code>package com.alpha.dealtap;
  
  import java.lang.reflect.Array;
  import java.util.List;
  import java.util.ArrayList;
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.text.Editable;
  import android.text.TextWatcher;
  import android.util.Log;
  import android.view.View;
  import android.widget.ArrayAdapter;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.ListView;
  
  import com.parse.FindCallback;
  import com.parse.Parse;
  import com.parse.ParseException;
  import com.parse.ParseObject;
  import com.parse.ParseQuery;
  
  public class Search_Page extends Activity {
  
      private ListView lv;
      private EditText et;
      public String listview_array[] = { "BudWeiser", "Dubra", "Corona",
              "Jack Daniels", "Smirnoff", "Keystone Light", "Natural Ice" };
      private ArrayList&lt;String&gt; array_sort = new ArrayList&lt;String&gt;();
      public ArrayList&lt;Object&gt; _arrayList = new ArrayList&lt;Object&gt;();
      int textlength = 0;
      ParseObject dealsObject;
      int n = 0;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.search_page);
  
          Parse.initialize(this, "vUz23Z6zdIL1jbxbVWeLpsSdu1ClTu3YiG30zTWY",
                  "4BTyoq1QQKows8qVJV7lvU3ZokSRrLFyOCPzffwJ");
  
          // Using this Parsequery...I can grab/locate the objects from the Parse
          // list...Here I grabbed the objects that have Burnettes and the price
          // of it
          // Eventually I may need to set a limit on how many results I will get
          // from the for loop....So far I think it is limited to 100 by default
          ParseQuery query = new ParseQuery("Deals");
  
          // query.whereEqualTo("Brand", "Burnettes");
          query.findInBackground(new FindCallback() {
  
              @Override
              public void done(List&lt;ParseObject&gt; objects, ParseException e) {
                  if (e == null) {
                      Log.d("Brand", "Retrieved " + objects.size() + " Brands");
                      for (ParseObject dealsObject : objects) {
                          // use dealsObject.get('columnName') to access the
                          // properties of the Deals object
  
                          Object brands = dealsObject.get("Brand").toString();
  
                          _arrayList.add(brands);
                          listview_array = _arrayList;
                          //Having trouble putting strings into an array list....Have to cast as ArrayList and then it causes error!
  
  
                          Log.d("Size", (String) dealsObject.get("Size"));
                          Log.d("Price", (String) dealsObject.get("Price"));
                          Log.d("Brand", (String) dealsObject.get("Brand"));
                          n++;
                      }
  
                  } else {
                      Log.d("Brand", "Error: " + e.getMessage());
                  }
              }
          });
  
  
  
  
          Button store = (Button) findViewById(R.id.b1);
          Button deal = (Button) findViewById(R.id.b2);
  
          lv = (ListView) findViewById(R.id.ListView01);
          et = (EditText) findViewById(R.id.search_box);
          lv.setAdapter(new ArrayAdapter&lt;Object&gt;(this,
                  android.R.layout.simple_list_item_1, listview_array));
  
          et.addTextChangedListener(new TextWatcher() {
              public void afterTextChanged(Editable s) {
                  // Abstract Method of TextWatcher Interface.
              }
  
              public void beforeTextChanged(CharSequence s, int start, int count,
                      int after) {
                  // Abstract Method of TextWatcher Interface.
              }
  
              public void onTextChanged(CharSequence s, int start, int before,
                      int count) {
                  textlength = et.getText().length();
                  array_sort.clear();
                  for (int i = 0; i &lt; listview_array.length; i++) {
                      if (textlength &lt;= listview_array[i].length()) {
                          if (et.getText()
                                  .toString()
                                  .equalsIgnoreCase(
                                          (String) listview_array[i].subSequence(
                                                  0, textlength))) {
                              array_sort.add(listview_array[i]);
                          }
                      }
                  }
                  lv.setAdapter(new ArrayAdapter&lt;String&gt;(Search_Page.this,
                          android.R.layout.simple_list_item_1, array_sort));
              }
          });
  
          store.setOnClickListener(new View.OnClickListener() {
              // When you use OnClickListener...you need the onClick method inside
              // of it
  
              @Override
              public void onClick(View arg0) {
                  // TODO Auto-generated method stub
                  startActivity(new Intent("com.alpha.dealtap.STOREPAGE"));
              }
  
          });
  
          deal.setOnClickListener(new View.OnClickListener() {
              // When you use OnClickListener...you need the onClick method inside
              // of it
  
              @Override
              public void onClick(View arg0) {
                  // TODO Auto-generated method stub
                  startActivity(new Intent("com.alpha.dealtap.DEALPAGE"));
  
              }
  
          });
  
      }
  
      protected void onListItemClick(ListView l, View v, int position, long id) {
  
          // Cheese equals the position for which item that is clicked...so it
          // depends on which item that is clicked
          String cheese = "TAPDEAL";
          try {
              Class ourClass = Class.forName("com.alpha.dealtap." + cheese);
              Intent ourIntent = new Intent(Search_Page.this, ourClass);
              startActivity(ourIntent);
          } catch (ClassNotFoundException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
      }
  
      @Override
      protected void onPause() {
  
          super.onPause();
      }
  </code></pre>