开发者

how to perform action(listener) from the function?

开发者 https://www.devze.com 2023-01-26 01:12 出处:网络
I use the following code to return the Scroll View from the function.That Scroll View contain number of check boxes . I call this function and it return the Scroll View correctly.But how to get the va

I use the following code to return the Scroll View from the function.That Scroll View contain number of check boxes . I call this function and it return the Scroll View correctly.But how to get the value if any of the check box is checked i need to perform some action.How to do this ?

Scroll View return Function:

 public ScrollView MyViewGroup(String[] Fields,int width,int height)throws Exception{   

    ScrollView sc=new ScrollView(context);
    sc.setLayoutParams(new LayoutParams(width,
            height));

    TableLayout tbl=new TableLayout(context);       

    for(int i=0;i<Fields.length;i++){       
        TableRow tr=new TableRow(context);          
        CheckBox ch=new CheckBox(context);
        ch.setId(i);
        ch.setText(Fields[i]);
        tr.addView(ch);
        tbl.addView(tr);            
    }

    sc.addView(t开发者_StackOverflowbl);
    return sc;      
}

and i use this function like the following way

  LinearLay.addView(MyGui.MyViewGroup(strarr[],200,200);

Note :

MyGui class i create TextViews,EditTexts,Buttons and ScrollView .By using this MyGui Class i create the GUI 's only.I have one activity myform .In that myform class when i click the submit button i need get the checked value's and get some other Edittext Values from the user and take action for the submit Button only.Is there any possibility to do this ????


You need to pass the Context of the UI elements as parameter to the method, and subscribe checkboxes to the OnClickListener event

so it would be something like

class clsLinearLay implements Button.OnClickListener {
....
// implement the method
}



LinearLay.addView(MyGui.MyViewGroup(this,strarr[],200,200);

public ScrollView MyViewGroup(Context ctx, String[] Fields,int width,int height)

CheckBox ch=new CheckBox(ctx);
ch.setOnClickListener(ctx); // this will fire in the context class when the state is changed
0

精彩评论

暂无评论...
验证码 换一张
取 消