我在列表视图中有一个选中的文本视图,每当我单击列表视图中的一个项目时,都会检查一个随机选中的文本视图(不一定是我按下的那个)这是我的代码
lv2.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
final CheckedTextView checkedTextView = (CheckedTextView) findViewById(R.id.checkedTextView1);
checkedTextView.toggle();
}
});
其中 lv2 是我的列表视图,而 checkedTextView1 是我在每个列表视图项中的检查视图。如何调用特定的checkedTextView。有我可以调用的数组格式吗?例如checkedTextView[1].toggle();
?
编辑这里是我的适配器
public class SpecialAdapter2 extends ArrayAdapter<String> {
private int[] colors = new int[] { R.drawable.row_background_grey,
R.drawable.row_background_white };
public SpecialAdapter2(Context context, int resource, String[] names) {
super(context, resource, names);
// TODO Auto-generated constructor stub
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
int colorPos = position % colors.length;
view.setBackgroundResource(colors[colorPos]);
return view;
}