title: Android adapter.getItem(position).getItemId() not working (The method getId() is undefined for the type Object)
body: <p>I have a listview and i am populating the data to the list view form DB using custom adapter. Its working fine, but when i click on the list item, i want to get the ID of the item which is clicked to pass it on to the next activity to do some stuff. But when i click on list item, i am not able to get the ID.
  Any idea why is this happening?</p>
  
  <p>my list listener:</p>
  
  <pre><code>    list.setOnItemClickListener(new OnItemClickListener() {
  
                  @Override
                  public void onItemClick(AdapterView&lt;?&gt; a, View view, int position,
                          long id) {
  
  
                      Intent intent = new Intent(MainActivity.this,
                              CountryActivity.class);
                       intent.putExtra("countryId", adapter.getItem(position).getId());//here i am getting error saying 
            //The method getId() is undefined for the type Object.
  
                      startActivity(intent);
  
                  }
              });
  </code></pre>
  
  <p>But i have defined my countries.java (POJO) for type specification</p>
  
  <pre><code>public class Countries {
      Integer id;
      String countryName = "", countryIcon = "";
  
      public Countries(Integer id, String countryName, String countryIcon) {
  
          this.id = id;
          this.countryName = countryName;
          this.countryIcon = countryIcon;
      }
  
      public Integer getId() {
          return id;
      }
  
      public void setId(Integer id) {
          this.id = id;
      }
  
      public String getCountryName() {
          return countryName;
      }
  
      public void setCountryName(String countryName) {
          this.countryName = countryName;
      }
  
      public String getCountryIcon() {
          return countryIcon;
      }
  
      public void setCountryIcon(String countryIcon) {
          this.countryIcon = countryIcon;
      }
  
  }
  </code></pre>
  
  <p>i am fetching data out of cursor obj (visas) from the below code:</p>
  
  <pre><code>names = new ArrayList&lt;Countries&gt;();
          do {
  
              country = new Countries(Integer.parseInt(visas.getString(0)),
                      visas.getString(1), visas.getString(2));
  
              // Log.d("VISA", visas.getString(0));
  
              names.add(country);
  
          } while (visas.moveToNext());
  </code></pre>
  
  <p>here is my adapter code:</p>
  
  <pre><code>public class VisaAdapter extends ArrayAdapter&lt;Countries&gt; {
      private final Context context;
      private final ArrayList&lt;Countries&gt; values;
      Resources resc = getContext().getResources();
  
      public VisaAdapter(Context context, ArrayList&lt;Countries&gt; values) {
          super(context, R.layout.list_item, values);
          this.context = context;
          this.values = values;
      }
  
      @Override
      public Countries getItem(int position) {
          return values.get(position);
      }
  
      @Override
      public long getItemId(int position) {
          return position;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          LayoutInflater inflater = (LayoutInflater) context
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
          View rowView = inflater.inflate(R.layout.list_item, parent, false);
          TextView textView = (TextView) rowView.findViewById(R.id.label);
          ImageView imageView = (ImageView) rowView.findViewById(R.id.logo);
          textView.setText(values.get(position).getCountryName());
  
          // Change icon based on name
          String icon = values.get(position).getCountryIcon();
          int resIcon = resc.getIdentifier(icon, "drawable", "com.m7.visaapp");
  
          rowView.setBackgroundResource(R.drawable.list_view_places_row);
  
          imageView.setImageResource(resIcon);
  
          return rowView;
      }
  
  }
  </code></pre>