我需要创建一个充满按钮的 ArrayList,它将链接到水平滚动布局。在将按钮文本插入 ArrayList 后,尝试更改按钮文本时出现 ResourceNotFound 错误:
public class Dictionary extends Activity implements Runnable, OnClickListener {
//Candidates
candidatesScrollView = (HorizontalScrollView) findViewById(R.id.activity_dictionary_horizontalScrollView1);
candidatesButtons = new ArrayList<Button>();
candidatesButtons.add((Button) findViewById(R.id.activity_dictionary_horizontalscrollview1_button1));
candidatesButtons.add((Button) findViewById(R.id.activity_dictionary_horizontalscrollview1_button2));
candidatesButtons.add((Button) findViewById(R.id.activity_dictionary_horizontalscrollview1_button3));
candidatesButtons.add((Button) findViewById(R.id.activity_dictionary_horizontalscrollview1_button4));
candidatesButtons.add((Button) findViewById(R.id.activity_dictionary_horizontalscrollview1_button5));
candidatesButtons.add((Button) findViewById(R.id.activity_dictionary_horizontalscrollview1_button6));
candidatesButtons.add((Button) findViewById(R.id.activity_dictionary_horizontalscrollview1_button7));
candidatesButtons.add((Button) findViewById(R.id.activity_dictionary_horizontalscrollview1_button8));
candidatesButtons.add((Button) findViewById(R.id.activity_dictionary_horizontalscrollview1_button9));
candidatesButtons.add((Button) findViewById(R.id.activity_dictionary_horizontalscrollview1_button10));
candidatesButtons.add((Button) findViewById(R.id.activity_dictionary_horizontalscrollview1_button11));
candidatesButtons.add((Button) findViewById(R.id.activity_dictionary_horizontalscrollview1_button12));
for(int i = 0; i < candidatesButtons.size(); i++)
((Button) candidatesButtons.get(i)).setOnClickListener(this);
(...)
}
我尝试在此方法中更改该属性:
private void recognize() {
(...)
byte buffer[];
buffer = RecogEngine.setResult(0); // and set the remaining data to engine
try {
candidatesString = new String(buffer, "UTF-8");
Button b;
for (int i = 0; i < candidatesString.length(); i++)
candidatesButtons.get(i).setText(candidatesString.charAt(i));
}
catch (Exception e) {
e.printStackTrace();
}
(...)
}
我究竟做错了什么?