starwar2012 2013-03-14 07:37 采纳率: 0%
浏览 2699

为checkBox添加监听器

在android类中动态创建了checkBox。要添加一个onclick 动作监听器上去。
应该怎么实现。

不是在activity中,是在类中创建的。

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;
    }
}
  • 写回答

1条回答

  • 狼孑野心 2013-03-16 02:35
    关注

    check[i]这就是你的checkbox组件,给他添加监听就可以了

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题