Hello everyone I need your help, I want in android studio press a button ("Start") and when I go to the second activity, I start to run the program that is random words
- I need to know how to make them go by one by one
- Where should I put the code to run when I press the button
- And also what are the elements so that the words are shown as a result in the second activity
Main Menu (Main_Activity)
Here I leave the code that I need to execute
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
public void BotonesPantallaPrincipal(View view){
String button_text;
button_text= ((Button) view).getText().toString();
if (button_text.equals("Comenzar")){
Intent intent = new Intent(this,Comenzar.class);
startActivity(intent);
TextView textView_click = (TextView) findViewById(R.id.textView_click);
}
else if (button_text.equals("Opciones")){
Intent intent = new Intent(this,Opciones.class);
startActivity(intent);
}
else if (button_text.equals("Buscar")){
Intent intent = new Intent(this,Busqueda.class);
startActivity(intent);
}
This is the code made in Eclipse that I need to run when the Start button is pressed
import java.util.Timer;
import java.util.TimerTask;
public class NombresAleatorios {
public static String [] generarNombresAleatorios(int cantidad) {
String [] nombresAleatorios = new String[cantidad];
String [] Abc= {
};
for (int i = 0; i < cantidad; i++) {
nombresAleatorios[i]= Abc[(int)(Math.floor(Math.random()*((Abc.length-1)-0+1)+0))];
}
return nombresAleatorios;
}
public static void imprimir(String [] nombresGenerados) {
for (int i = 0; i < nombresGenerados.length; i++) {
System.out.println(nombresGenerados[i]);
}
}
public static void main(String[] args) {
Timer timer2= new Timer();
TimerTask tarea = new TimerTask() {
public void run() {
imprimir(generarNombresAleatorios(1));
}
};
timer2.schedule(tarea, 5000, 5000);
}
}