0

Below is a method in OnClickListner. I want to pass first 1=0, then i=1 likewise.

But below code shows only i=0;

            @Override
            public void onClick(View v) {
                for(i=0; i<shopTelNos.length;i++){
                    Toast.makeText(c.getApplicationContext(),"value is : "+i,Toast.LENGTH_SHORT).show();
                    break;
                }
            }
        });

Help me on this.

5
  • why there is a break; ? Give some delay in your for loop. Otherwise you will not be able to see the Toasts. As for loop will execute faster than Toast display time Commented May 10, 2016 at 12:23
  • 1
    what is your shoptel array length, even if its 2, it will loop only once. coz yur condition is less than. Commented May 10, 2016 at 12:23
  • @tenten Remove break; statement and try Commented May 10, 2016 at 12:27
  • @Raghavendra I tried but that increments the i Commented May 10, 2016 at 12:29
  • I'm little confused clarify me please. Without incrementing how you will get i value 1 its always 0 right? Commented May 10, 2016 at 12:30

3 Answers 3

1

I think the break is causing to stop after the first iteration on the loop. Try to remove the break and retest. it should do the trick

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

Comments

0

Are you sure shopTelNos.length is more than 1? The for loop you have made loops through all the elements in the shopTelNoss array. If there is only one element in that array, it will only display the message once.

Comments

0

First, either debug or print and check the array and its length to confirm its contents:

Log.i("ShopTel", "Array :" +shopTelNos);
Log.i("ShopTel", "Array size :" +shopTelNos.length);

Second, put a delay in between the toasts. The toasts may be overlapping.

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.