我正在尝试显示基于RadioButtons
. 我使用 2 组按钮。该按钮应指向[x, y]
我的数组。String
应该显示数组的值(使用 a Toast
)。
是的,我对此很陌生,但我试图挑选几个类似的例子,但运气不佳。
public class MainActivity extends Activity {
String[][] tipSize = {
{"N/A","N/A","Pink","Lt Blue","Purple","Yellow","Brown","Orange","Tan","Blue","White","Beige"},
{"N/A","Pink","Lt Blue","Purple","Yellow","Brown","Orange","Green","Tan","Blue","White","Beige"},
{"N/A","N/A","Pink","Purple","Turquoise","Yellow","Green","Tan","Blue","White","Red","No Tip"},
{"Pink","Lt Blue","Purple","Yellow","Orange","Green","Tan","Blue","Red","Beige","Gray","N/A"},
{"Pink","Lt Plue","Purple","Orange","Green","Tan","Blue","White","Beige","Black","Gray","N/A"},
{"Pink","Lt Blue","Yellow","Brown","Orange","Green","Tan","Blue","White","Beige","Black","N/A"},
{"Pink","Lt Blue","Yellow","Brown","Tan","Blue","White","Red","Beige","Black","No Tip","N/A"},
{"Pink","Lt Blue","Purple","Yellow","Orange","Green","Tan","Blue","Red","Beige","Gray","N/A"},
};
private RadioGroup dispenser,ounce_pg;
private RadioButton disp,o_pg;
String tip = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button finishBtn = (Button) findViewById(R.id.button1);
finishBtn.setOnClickListener (new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
MainActivity.this.showit();
}
});
}
protected void showit() {
// TODO Auto-generated method stub
disp = (RadioButton) findViewById(R.id.dispenser);
o_pg = (RadioButton) findViewById(R.id.ounce_pg);
tip = String tipSize [disp,o_pg];
// tip is the displayed answer (Color of tip), tipSize[][] is the Array, disp is RadioButton 1 - o_pg is Radio Button 2 values.
Toast.makeText(MainActivity(),tip,Toast.LENGTH_LONG).show();
}
}