我想使用代码设置我的滚动视图元素。这是我到目前为止所拥有的(注释代码不起作用):
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");
for (int i = 0; i < candidatesString.length(); i++)
{
candidatesButtons.get(i).setTextColor(getResources().getColor(R.color.Celadon));
candidatesButtons.get(i).setTypeface(null,Typeface.BOLD);
candidatesButtons.get(i).setText(String.valueOf(candidatesString.charAt(i)));
}
catch (Exception e) {
e.printStackTrace();
}
//HERE_I_WANT_TO_SELECT_AND_HIGHLIGHT (like in default HOLO_DARK THEME)
//candidatesButtons.get(0).requestFocus();
//candidatesButtons.get(0).setSelected(true);
(...)
}
这个怎么做?