0
こんにちは私はここでボタンをクリックすると1つのアプリをやっています。私は1つの文字列配列を使用して私はdisplyテキストビューで1つのvalue.andランダムfunを適用しても、同じページ別の場所私は、A、B、Cのようないくつかのボタンをdisplyする必要がありますfine.私は 'ボタン'をクリックすると、ボタンの値とテキストビューの値を比較する必要があることを意味します。最初のボタン 'a'には、テキストビューでも 'a 'ボタンがhighlet.buttonとtextviewの値がequlesでなくてはならないというような何らかのアクションを実行する必要があるということは、何も実行する必要がないということです。私はありがとうはTREIDコードの下に使用したが、II uはいずれかが私を提案することができgetting.pleaseないです...ボタン配列の文字列を文字列配列と比較してandroidでonclickを実行することができない
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);
}
}
}
仕事が – user1083266
場合は、答えの左側の投票ボタンの下の右の記号をマークすることで、この答えを正しいと受け入れることができます。これはあなたと他のユーザーのSOに役立ちます。 – user370305
上記の例では、皿の配列にランダムな楽しみを加える必要もあります.i set String q1 = dishes [rgenerator.nextInt(dishes.length)];このように[i] .setText(q1);ランダムな楽しい作業。しかし、すべてのボタンが同じvalues.but私はdiffの値を持つすべてのボタンが必要 – user1083266