title: Android : Display details of Item in list view when clicked
body: <p>I am working on an Android project, where I am displaying a list of items for the user. Now, what I am trying to do is when the user clicks on the item, I want the ID of that item, so that I can call upon the Object details via the network and display them in another activity. Now the problem is, the object displayed contain only the names. I cannot find a way, to set the ID of the item, which is hidden, and then I can retrieve that when the user clicks and do the subsequent task. Is there any way to set the id somewhere which cannot be seen by the user and can be used. </p>
  
  <p>Here is the code :</p>
  
  <pre><code>public class RestaurantList extends Activity {
  
      String restaurantList = "http://192.168.178.60:8080/restaurant/listing";
  
      private ResponseEntity&lt;RestRestaurant[]&gt; responseEntity;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
  
          ListView listView = (ListView) findViewById(R.id.restRestaurantList);
  
          super.onCreate(savedInstanceState);
          setContentView(R.layout.restos);
         RestTemplate restTemplate = StaticRestTemplate.getRest();
  
          Thread thread = new Thread(new Runnable() {
              @Override
              public void run() {
                  HttpHeaders requestHeaders = new HttpHeaders();
                  requestHeaders.add("Cookie", "JSESSIONID=" + StaticRestTemplate.jsessionid);
                  requestHeaders.setAccept(Collections.singletonList(new MediaType("application", "json")));
                  HttpEntity&lt;?&gt; requestEntity = new HttpEntity&lt;Object&gt;(requestHeaders);
                  restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
                  responseEntity= restTemplate.exchange(restaurantList, HttpMethod.GET,requestEntity,RestRestaurant[].class);
              }
          });
          thread.start();
          ProgressDialog progress = new ProgressDialog(this);
          progress.setTitle("Loading");
          progress.setMessage("Wait while loading...");
          while (thread.getState()!=Thread.State.TERMINATED){
              progress.show();
          }
          progress.dismiss();
  
          RestRestaurant[] restRestaurantList = responseEntity.getBody();
          ArrayList&lt;String&gt; list = new ArrayList&lt;&gt;();
  
          for (RestRestaurant restRestaurant1 : restRestaurantList){
              Log.d("RestRestaurant name", restRestaurant1.getRestaurantName());
              list.add(restRestaurant1.getRestaurantName());
          }
  // I am getting error at below line, saying StableArrayAdapter cannot be applied to RestRestaurant. 
          final StableArrayAdapter adapter = new StableArrayAdapter(this,
                  android.R.layout.simple_list_item_1, list);
          listView.setAdapter(adapter);
  
          listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, final View view,
                                      int position, long id) {
                  final String item = list.get(position);
                  view.animate().setDuration(2000).alpha(0)
                          .withEndAction(new Runnable() {
                              @Override
                              public void run() {
  
  
  
                              }
                          });
              }
  
          });
      }
  
      private class StableArrayAdapter extends ArrayAdapter&lt;RestRestaurant&gt; {
  
          HashMap&lt;Integer, Integer&gt; mIdMap = new HashMap&lt;Integer, Integer&gt;();
  
          public StableArrayAdapter(Context context, int textViewResourceId,
                                    List&lt;RestRestaurant&gt; objects) {
              super(context, textViewResourceId, objects);
              for (int i = 0; i &lt; objects.size(); ++i) {
                  mIdMap.put(objects.get(0).getRestaurantId(), i);
              }
          }
  
          @Override
          public long getItemId(int position) {
              RestRestaurant item = getItem(position);
              return mIdMap.get(item);
          }
  
          @Override
          public boolean hasStableIds() {
              return true;
          }
  
      }
  
      @Override
      public void onBackPressed()
      {
          Intent intent = new Intent(RestaurantList.this, Login.class);
          StaticRestTemplate.jsessionid = null;
          StaticRestTemplate.replyString = null;
          startActivity(intent);
          finish();
      }
  }
  </code></pre>
  
  <p>xml file :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent"&gt;
  
      &lt;ListView
              android:layout_width="match_parent"
              android:layout_height="457dp"
              android:id="@+id/restRestaurantList" android:layout_gravity="center_horizontal"
              android:layout_marginTop="20dp"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Kindly let me know what I am doing wrong. </p>