title: Pass java object to new android instance on list view click
body: <p>I have a list view populated by json returned from an api. As I parse the json I create a new java object that gets added to an array list. The array list is then used to build the list view. I can currentley click on an item in the list view and get a toast saying an item was clicked. </p>
  
  <p>I would like to to be able to retrieve the individual object so I cna pass the object to a new instance and load all the objects details on a new instance to display to a user. How can I pass an object on like this?</p>
  
  <p>My Code:</p>
  
  <pre><code>private class ReadJSONResult extends AsyncTask
      &lt;String, Void, String&gt; {
          protected String doInBackground(String... urls) {
              return readJSONFeed(urls[0]);
          }
  
          protected void onPostExecute(String result) {
              try {
                  System.out.println(result);
                  Log.d("asycTask", "[ Gets into asyc task ]");
                  ///get 
                  Log.d("search", "[ check if we get search results ]");
                  Log.d("search", "[" + result + "]");
  
                  JSONObject json = new JSONObject(result);
  
                  //acces listview
                  lv = (ListView) findViewById(android.R.id.list);
  
                  //make array list for beer
                  List&lt;BeerData&gt; beerList = new ArrayList&lt;BeerData&gt;();
  
  
  
                  //get json items
                  for(int i = 0; i &lt; json.getJSONArray("data").length(); i++) {
  
                      String beerId = GetBeerDataFromJSON(i,"id", json);
                      String beerName = GetBeerDataFromJSON(i,"name", json);
                      String beerDescription = GetBeerDataFromJSON(i,"description" , json);
                      String beerAbv = GetBeerDataFromJSON(i,"abv" , json);
                      String beerIbu = GetBeerDataFromJSON(i,"ibu" , json);
                      String beerIcon = GetBeerIconsFromJSON(i, "icon",json );
                      String beerMediumIcon = GetBeerIconsFromJSON(i, "medium",json );
                      String beerGlass = GetBeerGlassFromJSON(i, json );
                      String beerStyle = GetBeerStyleFromJSON(i,"name", json );
                      String beerStyleDescription = GetBeerStyleFromJSON(i,"description", json );
                      String beerBreweryId = GetBeerBreweryInfoFromJSON(i, "id", json );
                      String beerBreweryName = GetBeerBreweryInfoFromJSON(i, "name", json );
                      String beerBreweryDescription = GetBeerBreweryInfoFromJSON(i, "description", json );
                      String beerBreweryWebsite = GetBeerBreweryInfoFromJSON(i, "website", json );
                      String beerBreweryYear = GetBeerBreweryInfoFromJSON(i, "established", json );
  
  
  
                      //create beer object
                      BeerData thisBeer = new BeerData(beerName, beerId, beerDescription, beerAbv, beerIbu, beerIcon,
                              beerMediumIcon, beerGlass, beerStyle, beerStyleDescription, beerBreweryId, beerBreweryName,
                              beerBreweryDescription, beerBreweryYear, beerBreweryWebsite);
  
                      //add beer to list
                      beerList.add(thisBeer);
  
  
                  }
  
                  //update listview
                  ArrayAdapter&lt;BeerData&gt; adapter1 = new ArrayAdapter&lt;BeerData&gt;(MainActivity.this, R.layout.list_item, R.id.itemName, beerList);
                  lv.setAdapter(adapter1);
  
                  //set up clicks
                  lv.setOnItemClickListener(new OnItemClickListener() {
  
  
                      @Override
                      public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1,
                              int arg2, long arg3) {
  
                          //on item click do this
                          Toast.makeText(MainActivity.this, "click worked", Toast.LENGTH_SHORT).show();
                      } 
                      });
  
  
  
  
  
  
              } catch (Exception e) {
                  Log.d("ReadBeerDataTask", e.getLocalizedMessage());
              }          
          }
      }
  </code></pre>