hi i am doing one app here when i click button that time i need to disaply a to z values in one textview radomly.in textview each time i need to display one value only.so i using one string array i disply in text view one value.and apply random fun also it working fine.then same page another place i need to disply some buttons like a,b,c….z.using anthoer string array i displyed those buttons.but the problem is when i click ‘a’ button means that time i need to compare button value to textview value, now in first button ‘a’ is there that in textview also ‘a’ is there means i need to perform some action like button should be highlet.button and textview values not equles means i need perform nothing. i treid using below code but i i am not getting.please can u any one suggest me…
ButtonList .class:
public class ButtonList extends Activity implements OnClickListener{
/** Called when the activity is first created. */
private static final Random rgenerator = new Random();
String[] dishes = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j"};
String[] dishes1 = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j"};
String q = dishes1[rgenerator.nextInt(dishes1.length)];
LinearLayout linear;
TableLayout table;
int dishQuantity =10;
TextView text1;
Button[] plus = new Button[dishQuantity];
TableRow[] row = new TableRow[dishQuantity];
String s1,s2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
linear = new LinearLayout(this);
text1 =new TextView(this);
text1.setText(q);
s1=text1.getText().toString();
table = new TableLayout(this);
linear.setOrientation(LinearLayout.HORIZONTAL);
for (int i=0; i<dishQuantity; i++) {
row[i] = new TableRow(this);
plus[i] = new Button(this);
plus[i].setText(dishes[i]);
plus[i].setOnClickListener(this);
row[i].addView(plus[i]);
table.addView(row[i],60,30);
s2=plus[i].getText().toString();
}
linear.addView(table);
linear.addView(text1);
setContentView(linear);
}
public void onClick(View v) {
// TODO Auto-generated method stub
if (s1.equals(s2)) {
((Button) v).setEnabled(false);
}
}
}
It nice if you get text from textview and button at on button’s click,