Java – how to add the final integer variable?
•
Java
Eclipse is providing final, but I can't add the I variable
@Override public void onClick(View v) { final TextView tv = (TextView) findViewById(R.id.tvSayac); int i = 1; do { try { new Thread(new Runnable() { public void run() { tv.post(new Runnable() { public void run() { tv.setText(Integer.toString(i)); } }); } }); i++; Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } while (i < 16); }
Solution
Final is an entity that cannot be changed after initialization
Final (Java)
What you can do is create a variable within the scope of the do / while loop, which is the final value of I and send it to the function
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码