title: How to access listview items generated by arrayadapter
body: <p>I have tied my application to Firebase database and after being able to display them I also want to be able to select them and access their textview values. However .getValue() does not work for views. I know that my code is very messy and my selector is only working one way, but can you help me to find out what is going on. I will add a screenshot to make things more clear. At the moment when clicking on one of the items int num = Integer.parseInt(text) gives an error and the app will crash because the value I get from view is "Android.widget...", not what I want to get.
  Screenshot pic:</p>
  
  <p><img src="https://s30.postimg.org/70ws0esqp/2014_07_18_07_37_09.png" alt="Screenshot"></p>
  
  <p>Orders.java</p>
  
  <pre><code>public class Orders extends ActionBarActivity {
      public final static String TOTAL_SUM = "com.nordscript.checkmate.SUM";
  
  // Declare the UI components
      private ListView foodList;
  
      // Declare an ArrayAdapter that we use to join the data set and the ListView
      // is the way of type safe, means you only can pass Strings to this array
      //Anyway ArrayAdapter supports only TextView
      private ArrayAdapter arrayAdapter;
  
      private Firebase ref;
      private Orders activ;
      private ArrayList&lt;String&gt; dishes;
      public int total;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      activ = this;
      dishes = new ArrayList&lt;String&gt;(20);
  
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_orders);
  
   // Initialize the UI components
      foodList = (ListView)findViewById(R.id.listView1);
  
      // Create a reference to a Firebase location
      ref = new Firebase("https://xxxxxxxxxx.firebaseio-demo.com/Restaurants/Restaurant 2/Tables/Table 2/Orders");
  
      // Read data and react to changes
      ref.addChildEventListener(new ChildEventListener() {
            @Override
            public void onChildAdded(DataSnapshot snapshot, String previousChildName) {
              Map s = snapshot.getValue(Map.class);
              dishes.add(snapshot.getName() + "  " + ((Map)snapshot.getValue(Map.class)).get("Price"));
              Log.i("Test", dishes.toString());
              arrayAdapter = new ArrayAdapter(activ, android.R.layout.simple_list_item_1, dishes.toArray());
  
              // By using setAdapter method, you plugged the ListView with adapter
              foodList.setAdapter(arrayAdapter);
            }
  
            @Override public void onChildChanged(DataSnapshot snapshot, String previousChildName) { }
  
            @Override public void onChildRemoved(DataSnapshot snapshot) {
              Map s = snapshot.getValue(Map.class);
              dishes.remove(snapshot.getName() + "  " + ((Map)snapshot.getValue(Map.class)).get("Price"));
              Log.i("Test", dishes.toString());
              arrayAdapter = new ArrayAdapter(activ, android.R.layout.simple_list_item_1, dishes.toArray());
  
              // By using setAdapter method, you plugged the ListView with adapter
              foodList.setAdapter(arrayAdapter);
            }
  
            @Override public void onChildMoved(DataSnapshot snapshot, String previousChildName) { }
  
            @Override
            public void onCancelled(FirebaseError arg0) { }
      });
  
      foodList.setOnItemClickListener(new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
              view.setBackgroundColor(Color.GREEN);
              String text = view.toString();
              text.replaceAll("[^\\d.]", "");
              int num = Integer.parseInt(text);
              total += num;
          }
      });
  }
  
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.orders, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
      if (id == R.id.action_settings) {
          return true;
      }
      return super.onOptionsItemSelected(item);
  }
  
  public void toPayment(View view) {
      Intent pay = new Intent(this, PaymentMethod.class);
      pay.putExtra(TOTAL_SUM, total);
      startActivity(pay);
  }
  
  
  }
  </code></pre>