0

I have done this code,

if (k == 21 && click1 == true)
{   
    for (k = 21; k < 39; k++) {
        Spinner sp = (Spinner) gridLayout.getChildAt(k);
        String value = (String) sp.getSelectedItem();
        Log.d("Spinner value als string", value);
        if (!value.isEmpty()) {
            value1 = Integer.parseInt(value);
            ("Spinner value als invert", ""+ value1);
            sum = sum + value1;
            Log.d("Totall Value", "" + sum);
        }
    }
}

Here the value k has been updated as 39 after iteration and i want use this value to a variable as 39 so that next this loop doesn't start again and I can use this to another loop or iteration. Help needed !!

3
  • 3
    But you know it's 39 since it's written in the loop.. Why don't you use... simply 39? Commented Dec 17, 2013 at 15:22
  • I didn't get it too... Also, if you're gonna use the k right after that, it's value will indeed be 39, so you can use it again. Commented Dec 17, 2013 at 15:24
  • i need to update value k after iteration cause after iteration i can compute total result through value from spinner and i can move on to next column where updated value will be use to compute another column for result calculation. Commented Dec 18, 2013 at 7:28

1 Answer 1

1

if I understood it correctly, what left for you is to declare this variable as a class-field.

public class YourClass {

    public int k = 0;

    public void yourMethod(){
        if (k == 21 && click1 == true)
        {   
            for (k = 21; k < 39; k++) {
                Spinner sp = (Spinner) gridLayout.getChildAt(k);
                String value = (String) sp.getSelectedItem();
                Log.d("Spinner value als string", value);
                if (!value.isEmpty()) {
                    value1 = Integer.parseInt(value);
                    ("Spinner value als invert", ""+ value1);
                    sum = sum + value1;
                    Log.d("Totall Value", "" + sum);
                }
             }
        }

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

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.