SwitchCell的OnChange

时间:2016-05-11 18:10:54

标签: xamarin xamarin.forms

我有一个带SwitchCell的TableView。我想向它添加一个OnChanged事件。我怎么会这样做?如果可能,我的代码如下:

private static final long serialVersionUID = 6596285522176538665L;

String record_holderName=null;
public UserRecords(){} 

public UserRecords(String name) {
    this.record_holderName=name;

    Connection con = null;
    PreparedStatement st=null;
     ResultSet rs=null;
     JTable myTable = new JTable();


    try {
        con = ConnectDb.getDbConnection();
        st=con.prepareStatement("select email,password,servicename,accounttype,hint,lastupdtime from usergems where record_holder=?");
        st.setString(1,record_holderName);
        rs = st.executeQuery();
        ResultSetMetaData md= rs.getMetaData();
        int columns=md.getColumnCount(); //holds number of column in resultSet

         DefaultTableModel model= new DefaultTableModel(); //this object pass data into JTables

        Vector<Object>columns_name=new Vector<Object>();
        Vector<Object>data_rows=new Vector<Object>();

        for(int i=1;i<columns;i++)
        {
            columns_name.addElement(md.getColumnName(i));
        }
        model.setColumnIdentifiers(columns_name);

        while(rs.next())
        {
            for(int j=1;j<columns;j++)
            {
                data_rows.addElement(rs.getString(j));
            }
            model.addRow(data_rows);
        }

        myTable.setModel(model);

          } catch(Exception e){
        String msg = "ClassNotFoundException: Not able to load the db drivers\n Details: \n" + e;
        JOptionPane.showMessageDialog(this, msg, "Error!", JOptionPane.ERROR_MESSAGE);
        System.exit(0);
    }finally{
        try{
            rs.close();
            st.close();
          con.close();
        }catch(Exception e){ 
            JOptionPane.showConfirmDialog(null, e);
        }
        }

    add(myTable);
    myTable.setPreferredScrollableViewportSize(new Dimension(800,500));
    JScrollPane pane =new JScrollPane(myTable);
    add(pane,BorderLayout.CENTER );/*myTable.getRowHeight()* myTable.getRowCount())*/
    //myTable.repaint();

}

1 个答案:

答案 0 :(得分:3)

您需要在创建时保留对switch类的引用,并使用它来分配处理程序:

O(1)