3

I am trying to create an application which dynamically lists installed applications in a gridview.I am able to display the applications in a gridview form but not able to make these application icons clickable. Nothing happens when i click these icons. The code inside the setOnItemClickListener does not get triggered on click event.

Part of code :

Class name dynamicgridactivity.java

 mGridMain.setOnItemClickListener(new OnItemClickListener() {     
    @Override
    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {           

        ViewHolder holder = (ViewHolder)v.getTag();  
        Log.i("view get tag" ,v.getTag().toString());

        if(holder == null) {  

              return;        } 


        Toast.makeText(dynamicgridactivity.this, "Hello", Toast.LENGTH_SHORT).show();    
                }    });

    }

Note: My application icons and text in gridview display are dynamic and not static as given in android examples.

Can Someone suggest me a sure working way of making grid items clickable.

3 Answers3

2

Do you have some kind of click listener on the grid itself, or on any of the parents of the grid or grid items? Have you set focusable or clickable to false on the individual grid items? Do you see the selector around the items when you click them?

you could also try just setting a view onClickListener on each item in the grid (admittedly less efficient).

Without being able to see xml or your adapter, its going to be a little hard to guess.

Sam Judd
  • 7,317
  • 1
  • 38
  • 38
1

Need to check the mGridMain declaration. Maybe the view o the parent are not correct

vgonisanz
  • 11,831
  • 13
  • 78
  • 130
  • i have followed the same way as given on android developer site [link] http://developer.android.com/resources/tutorials/views/hello-gridview.html Just that in developer site they are using static images and my application is displaying installed applications dynamically – anurag jain Dec 27 '11 at 06:46
0

Just make sure you dont have itemclick listeners anywhere else in the grid

Archie
  • 161
  • 1
  • 8