我在Android类中动态创建CheckBox动作(Not Activity)。所以我需要将onClick
Action Listener添加到我的复选框,如何实现这一点。为动态创建的CheckBox添加点击动作侦听器
我正在使用以下代码。
public class DataBaseAdapter extends SQLiteOpenHelper
{
...//onCreate and onUpdate
...
...
public TableLayout getAllAlarmList(Context con)
{
TableLayout tb = new TableLayout(con);
TableRow[] tr = new TableRow[maxCount]; //maxCount is the number of rows
CheckBox[] check = new CheckBox[maxCount]; //maxCount is the number of rows in the database.
for(int i=0;i<maxCount;i++)
{
tr[i]=new TableRow(con);
check[i]= new CheckBox(con); //con is Context class passed as argument.
check[i].setText(Integer.toString(i));
check[i].setId(100+i);
// I have to add onClick Action Listener here.
tr[i].addView(check[i]);
tb.addView(tr[i]);
}
return tb;
}
}
为此,我也在跟踪复选框的ID。
什么问题ü越来越设置'检查[I] .setOnCheckedChangeListener'的复选框 – 2013-03-14 05:33:44
,因为它不是一个Activity类,因此,无法写入 '检查[I] .setOnCheckedChangeListener(新onCheckedChangeListener)' 由于类不扩展查看类 – 2013-03-14 05:37:30