3

I have a list of image in grid view.When i click the image it shows in full screen mood and with touch change one image to another just increasing position.here is the code for onTouchListener

private int position=0;
imageView.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event)   
    {  
        if(event.getAction() == MotionEvent.ACTION_DOWN)  
        {  
              position++;
              if( v == findViewById( R.id.full_image_view ))   
              { 
                   imageView.setImageResource(imageAdapter.mThumbIds[position]);
              }
        }
        return false; 
    }
}); 

At the last image it it shows error that "it has stopped unexpectedly ".How can i handle the array of index bound?

2 Answers 2

4

you are try to get index that not in your array.your position must be less than array.length

 if( v == findViewById( R.id.full_image_view ))
              {
                  if(position < imageAdapter.mThumbIds.length){

                    imageView.setImageResource(imageAdapter.mThumbIds[position]);

                 }
               }
Sign up to request clarification or add additional context in comments.

Comments

0

Check that the index is valid (between 0 and array.size - 1 inclusive) before attempting to access that element in the array.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.