我試圖根據RadioButtons
顯示數組的內容。我使用2組按鈕。該按鈕應指向我陣列中的[x, y]
。應顯示數組的String
值(使用Toast
)。Android 2D陣列
是的,我在這方面是新手,但我試圖挑選幾個類似的例子,運氣不大。
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();
}
}
什麼是你的問題? – 2013-03-10 01:16:12
我知道語法錯了,但我留下來試着展示我看的方向。 感謝您的幫助。 – user2152750 2013-03-10 16:05:21
如果語法錯誤,您的編譯器錯誤是什麼? – 2013-03-10 21:24:59