• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

get clicked item of gridview to access it from getView in Adapter

Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just created a city object with other essential things like tourist places. I used arraylist in the Arraylist .

There is any object in the arrayslist .Here is the code below.

City city = new City();


       AttactivePlaces londonAttactivePlaces_one =new AttactivePlaces();
       londonAttactivePlaces_one.setPlaceName("Big Ben");
       londonAttactivePlaces_one.setPlaceDetailInformation("Big Ben");


CityAdapter cityAdapter = new CityAdapter(this,cityArraylist,R.color.mainBackground);

       GridView gridView = (GridView) findViewById(R.id.gridlist);

       gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
           public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {

               switch (position){

                   case 0:
                       Intent intent = new Intent(MainActivity.this,AttactivePlacesActivity.class);


ArrayList<City> cityAttactivePlaces = new ArrayList<City>();

       cityAttactivePlaces = MainActivity.cityArraylist;

       AttractivePlacesAdapter attractivePlacesAdapter = new AttractivePlacesAdapter(this,cityAttactivePlaces,R.color.mainBackground);

       ListView listView = (ListView) findViewById(R.id.listviewAttactivePlaces);



public class AttractivePlacesAdapter extends ArrayAdapter<City> {

   private int mBackgroundColor; // BackGround Color For each Activity

   public AttractivePlacesAdapter(Context context, ArrayList<City> resources, int color) {
       // Here, we initialize the ArrayAdapter's internal storage for the context and the list.
       // the second argument is used when the ArrayAdapter is populating a single TextView.
       // Because this is a custom adapter for two TextViews , the adapter is not
       // going to use this second argument, so it can be any value. Here, we used 0.
       // 0 -> list item layout resource ID
       super(context,0 ,resources);
       mBackgroundColor = color;

   // get list item from getView

    * Provides a view for an AdapterView (ListView, GridView, etc.)
    * @param position The position in the list of data that should be displayed in the
    *                 list item view.
    * @param convertView The recycled view to populate.
    * @param parent The parent ViewGroup that is used for inflation.
    * @return The View for the position in the AdapterView.
   public View getView(int position, View convertView, ViewGroup parent) {

       // Check if the existing view is being reused, otherwise inflate the view
       View listview = convertView;
       if (listview == null) {
           // parent -> listView   false -> we don't want to attach list item to parent
           listview = LayoutInflater.from(getContext()).inflate(R.layout.layout, parent, false);

       // get position of item to city
       //City city = getItem(position);

       ArrayList<City> cityArrayList = MainActivity.cityArraylist;

       City city = cityArrayList.get(1);

       for(int i=0;i<city.getAttactivePlaces().size();i++){

           // City Information
           TextView name = (TextView) listview.findViewById(R.id.bilgi_text_view);

           // Picture of City
           ImageView image = (ImageView) listview.findViewById(R.id.image_image_view);

           // Check whether the picture is or not.
           if (city.hasImage()) {
           } else {


       // City Information
       //TextView name = (TextView) listview.findViewById(R.id.name);



       // Picture of City
       //ImageView image = (ImageView) listview.findViewById(R.id.image_image_view);

       // Check whether the picture is or not.
       //if (city.hasImage()) {
       //    image.setImageResource(city.getAttactivePlaces().get(0).getmAttaticePlaceImageResourceId());
       //} else {
       //   image.setVisibility(View.GONE);

       // Set theme color for the list item
       View textContainer = listview.findViewById(R.id.text_container);

       // Find the color that the resource ID maps to
       int color = ContextCompat.getColor(getContext(), mBackgroundColor);

       // Set Background color to view

       return listview;



When I clicked any item of gridview, list informaiton of this item.  I ask it to many platform but not required response is occured.

How do I access clicked item' position  of gridview form AttractivePlacesAdapter.

I will apprecate you if you answer my quesiton and show the solution step by step.
Saloon Keeper
Posts: 27863
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This looks like an Android question. Moving to a more appropriate forum.
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic