虽然我很清楚我不可能在我的 onClick 方法中引用非最终变量,但我很想知道如何解决我目前面临的问题。
我有一个 ArrayAdapter。如果用户按下复选框 AsyncTask 并且用户订阅或取消订阅队列,这取决于复选框是否被选中。
我希望此状态反映在我的 txtStatus TextView 文本中的每个项目中。如何根据复选框的状态设置 TextView 的文本?
这是我的 getView 方法的部分代码:
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View row = convertView;
final CheckBox queueCBox;
userControl = new UserController(context);
final String queueName = data[position].label;
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
final QueueHolder holder = new QueueHolder();
holder.queuecbox = (CheckBox)row.findViewById(R.id.queues_item_checkbox);
queueCBox = (CheckBox)row.findViewById(R.id.queues_item_checkbox);
holder.txtLabel = (TextView)row.findViewById(R.id.queues_item_label);
holder.txtStatus = (TextView)row.findViewById(R.id.queues_item_status);
holder.queuecbox.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
final String[] param = new String[1];
param[0] = queueName;
if(queueCBox.isChecked())
{
holder.txtStatus.setText("Tilmeldt");
Log.d("ClickTest","SWITCH ON");
new JoinQueueTask().execute(param);
}
else
{
holder.txtStatus.setText("Frameldt");
Log.d("ClickTest","SWITCH OFF");
new LeaveQueueTask().execute(param);
}
}
});
row.setTag(holder);
}
else
{
final QueueHolder holder = (QueueHolder)row.getTag();
}
QueueItem queue = data[position];
String name = queue.label.replace("-", " ");
holder.txtLabel.setText(name); // holder cannot be resolved
holder.queuecbox.setChecked(queue.value); // holder cannot be resolved
return row;
}