all
I have difficulty in linking the two activities by using two buttons. The first button serves to select the item in the array. The second function button to proceed to the next page if the text appears on the first button “string 1”
What should I add in my code
This code in array.xml for button3
<string-array name="myArray">
<item>string 1</item>
<item>string 2</item>
<item>string 3</item>
<item>string 4</item>
<item>string 5</item>
This code in beta.java
private String[] myString;
private static final Random rgenerator = new Random();
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.next);
Resources res = getResources();
myString = res.getStringArray(R.array.myArray);
Button btn2;
btn2 = (Button)findViewById(R.id.button3);
btn2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
final String q = myString[rgenerator.nextInt(myString.length)];
((Button) v).setText(q);
}
});
Button btn3;
btn3 = (Button)findViewById(R.id.button4);
btn3.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
});
}
}
What should I add in button4 to be able to go to the next page if the text in the button3 perform “String 1”
First thing use the final keyword before button btn2 like
and use the following code at click of button btn 3