0

I have a gallery which contains one textview and imageview. If i set OnClickListener on Imageview , Gallery stops scrolling. I need a clickable and scrollbale gallery where user can click either on imageview or textview will shows the next activity of application.

In onClick event i want to pass some data to next activity via bundle. If i call onClick outside of the ImageAdapter class i cant pass the data to next activity.

If i put holder.image or gallery instead of holder.text. gallery stops scrolling.

Please suggest me some solution so that i can click image as well as text and at the same time i can scroll the gallery.

Neha
  • 414
  • 1
  • 4
  • 14

1 Answers1

1

No, no, no...you shouldn't put your onClickListener in your getView(). What you should do is something like:

gallery.setOnClickListener();

and inside this onClickListener(), retrieve the index of the item clicked. In code you showed you just overcharge the touch area so it breaks everything.

--edit

Here's what you can do :

Gallery gallery = (Gallery) findViewById(R.id.top_gallery);
    gallery.setAdapter(new ImageAdapter(this));
    gallery.setOnItemClickListener(new OnItemClickListener()
    {
        public void onItemClick(AdapterView parent, 
                View v, int position, long id) 
                {
                    TextView tView = (TextView) findViewById(R.id.cat_desc);
                    switch(gallery.getSelectedItemPosition())
                    {   
                    //do your stuff here...
                    }
    }  
Cehm
  • 1,502
  • 1
  • 12
  • 14