Reputation:
here is my code:
public void generujCislo(int pocetCislic)
{
TextView generovaneCislo = (TextView)findViewById(R.id.generujCislo);
Random random = new Random();
String nahodnaCislice;
int jedenCyklus = 0;
while(pocetCislic>jedenCyklus)
{
nahodnaCislice = String.valueOf(random.nextInt(10 - 0) + 0);
nahodnaCisla = nahodnaCisla + nahodnaCislice;
jedenCyklus++;
}
generovaneCislo.setText((nahodnaCisla));
zadaniCisel();
}
How I can use String nahodnaCisla with generated value in other class and there setText to new TextView? Thanks for answer.
Upvotes: 0
Views: 135
Reputation: 4290
Create an util class, with method that will provide needed value:
public final class Utils {
private static String nahodnaCisla;
public static String get(int pocetCislic) {
Random random = new Random();
String nahodnaCislice;
int jedenCyklus = 0;
while(pocetCislic>jedenCyklus)
{
nahodnaCislice = String.valueOf(random.nextInt(10 - 0) + 0);
nahodnaCisla = nahodnaCisla + nahodnaCislice;
jedenCyklus++;
}
return nahodnaCisla;
}
}
If you need the same value in every view, use a static variable to hold it in util class.
Use like this:
TextView generovaneCislo = (TextView)findViewById(R.id.generujCislo);
generovaneCislo.setText(Utils.get(pocetCislic));
Change names of methods as needed.
Upvotes: 1