1

As a requirement, I need to click an item only for zig zag position for gridview.

 gridView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View v,
                int position, long id) {
                    if (position% 2 == 0) {//0 even 1 odd..
    }
   }

This provides me for even items to click. How to get items in zig zag position?

 0 1
 2 3
 4 5
 6 7
 means in zig zag maaner 0,3,4,7 and so on position..

I couldn't get any idea how to proceed.

Thanks

Shiv
  • 129
  • 3
  • 12

1 Answers1

-1

This is a great tutorial on how to use an ImageAdapter to specify the positions of images in a GridView.

You need to specify an algorithm that addresses the images according to their number, the pattern you have is 0, 3, 4, 7 etc.

This is the same as saying:

"Start at 0, add 3, then add 1, then add 3, then add 1 etc..."

You can set the "clickable" property to false for each ImageView you don't want people to click on to prevent people clicking the images.

android:clickable="false"

Community
  • 1
  • 1
  • i can get the position etc., but please go through the question. i need to get toast for items in zig zag positions only. I don't know the [logic](http://rosettacode.org/wiki/Zig-zag_matrix#Translation_of:_Java_.28but_with_zero-based_indexes_and_combining_the_even_and_odd_cases.29) how to implement. these are all dynamically generating.. so i can't give fixed position. – Shiv Aug 30 '14 at 19:51
  • http://stackoverflow.com/questions/12734793/android-get-position-of-clicked-item-in-gridview is how you can get positions of clicked items, is that what you are asking? Please be clear. – Ḟḹáḿíṅḡ Ⱬỏḿƀíé Aug 30 '14 at 19:54
  • very simple way..my items are arranged in gridview as 0,1,2,3,4 etc.,(2*2) and so on..now i need to click only items which are in this 0,3,4,7,8,11,12,15,16,19,20 and so on which forms zig zag matrix type. – Shiv Aug 30 '14 at 19:57
  • You mean only those images should be clickable? – Ḟḹáḿíṅḡ Ⱬỏḿƀíé Aug 30 '14 at 19:58
  • yes in the order of that mentioned items in 2*2 grid. – Shiv Aug 30 '14 at 19:59
  • what is this? start at 0, then add 1 then add 3 then add 1 etc.,?? that I also know.how to implement that? not a proper solution by you.sorry. – Shiv Aug 30 '14 at 20:17
  • The first image you want is at position 0. Then you add 3 to 0 to get the position of the next image you want, which is position 3. Then you add one to 3 to get 4. Do you want somebody to write the code for you? – Ḟḹáḿíṅḡ Ⱬỏḿƀíé Aug 30 '14 at 20:19
  • yes i need to provide a piece of code how to use in for loop not by giving a blank non programming statement.if not, hope will wait for a better solution for this. thanks anyway. @Bennef – Shiv Aug 30 '14 at 20:26