Variable | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Variable

I had introduced an int in a onclicklistener method and told that what is that and now I want to use that int in other onclicklistener method but I can't play help me.

26th Nov 2016, 3:21 AM
amin ahrami
amin ahrami - avatar
3 Answers
0
package com.mycompany.myapp3; import android.app.*; import android.os.*; import android.widget.*; import android.view.*; import java.util.*; public class MainActivity extends Activity { Button cheak , bted; EditText ed1, ed2 ,edcheak; TextView tvcheak , tvstat; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); init(); } public void go(View v ){ String n = ed1.getText().toString(); int num =Integer.parseInt(n); Random random = new Random(); int zotopia = random.nextInt(num) +1; String rr = String.valueOf(zotopia); Toast.makeText(this , "",Toast.LENGTH_LONG).show(); tvstat.setText(""); } public void cheak (View v){ String gn =edcheak.getText().toString(); int gnn = Integer.parseInt(gn); String nc =String.valueOf(gnn); if(gnn == zotopia){ tvcheak.setText("hi"); }else{ tvcheak.setText("good"); } } private void init() { bted = (Button) findViewById(R.id.bted); cheak = (Button) findViewById(R.id.cheak); ed1 =(EditText) findViewById(R.id.ed1); edcheak =(EditText) findViewById(R.id.edcheak); tvstat =(TextView) findViewById(R.id.tvstat); tvcheak = (TextView) findViewById(R.id.tvcheak); } }
26th Nov 2016, 4:11 PM
amin ahrami
amin ahrami - avatar
0
this is my code I want to use (int zodopia) in method go, in method cheak
26th Nov 2016, 4:13 PM
amin ahrami
amin ahrami - avatar
0
when the button go pushed it will find a random number then in next method I described an if statement that will tell when the button checked was clicked what happen, if the the int Zootopia was higher or lower that the input number in edit text
26th Nov 2016, 4:21 PM
amin ahrami
amin ahrami - avatar