Here is the program as I have it thus far. It outputs a random number in one text field, but I need it to output a random array element in another field, both on the same button click. My array is saved as core.xml under the values section.
import android.content.res.Resources;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.util.Random;
public class Core extends ActionBarActivity {
Random rndNumbers = new Random();
int d20 = rndNumbers.nextInt(11) + 10;
Button random;
TextView display;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_core);
random = (Button)findViewById(R.id.btnNext);
display = (TextView)findViewById(R.id.txtNumber);
random.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View arg0){
d20 = rndNumbers.nextInt(11) + 10;
display.setText("Workout Reps " + d20);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_core, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);