-1

我在表格行中添加一个动态radiobutton显示数据的行。db我想通过单击来编辑行radiobutton。如何识别radiobutton点击了哪一行?

String selquery = "select * from student";
Cursor cursor = StudentDB.rawQuery(selquery,null) ;
if(cursor != null){
    if ((cursor != null && cursor.getCount()< 1))
    {
        cursor.close();
    }else{

        int numberOfRecords = cursor.getCount();
        cursor.moveToFirst();
        TableLayout table = (TableLayout)dialog.findViewById(R.id.datatablellayout);
        for(int i=0;i< numberOfRecords;i++){
            // Inflate your row "template" and fill out the fields.
            TableRow row = (TableRow)LayoutInflater.from(SampleDbAct.this).inflate(R.layout.tablewithrow, null);
            ((TextView)row.findViewById(R.id.datatable_name)).setText(cursor.getString((cursor.getColumnIndex("name"))));
            ((TextView)row.findViewById(R.id.datatable_rno)).setText(cursor.getString((cursor.getColumnIndex("roll_number"))));
            ((TextView)row.findViewById(R.id.datatable_place)).setText(cursor.getString((cursor.getColumnIndex("place_name"))));
            ((TextView)row.findViewById(R.id.datatable_class)).setText(cursor.getString((cursor.getColumnIndex("class"))));
            ((TextView)row.findViewById(R.id.datatable_email)).setText(cursor.getString((cursor.getColumnIndex("e_mail"))));
            ((RadioButton)row.findViewById(R.id.radio_btn)).setText(cursor.getString((cursor.getColumnIndex("e_mail"))));
            table.addView(row);

            /*System.out.println("You have entered the Name as:" +cursor.getString((cursor.getColumnIndex("name")))+":");
            System.out.println("You have entered the Roll No as:" +cursor.getString((cursor.getColumnIndex("roll_number"))));
            System.out.println("You have entered the Class as:" +cursor.getString((cursor.getColumnIndex("class"))));
            System.out.println("You have entered the place as:" +cursor.getString((cursor.getColumnIndex("place_name"))));
            System.out.println("You have entered the email as:" +cursor.getString((cursor.getColumnIndex("e_mail"))));*/

            if(!cursor.isLast())
                cursor.moveToNext();
        }
        table.requestLayout();
        cursor.close();
    }
}

StudentDB.close();
4

1 回答 1

0

您可以通过使用 button.setOnClickListener 设置其 onClickListener 来检测单选按钮的点击。当监听器被调用时,它会传入被触摸的视图。如果仅视图还不够,您可以使用视图的标记传递一些信息,以确定行的数据(通常是数组索引或生成行的对象),使用 setTag() 和 getTag()。

于 2013-03-22T06:07:41.823 回答