Reputation: 7900
I am new to android, I have a list view with multiple radio buttons. These radio buttons are created dynamically without any ID. I want to have a click listeners on these buttons, if any radio button is clicked then it should run some function, so how do I do it? Is it possible?
Upvotes: 1
Views: 1010
Reputation: 80
In the getView of your listviews adapter create the RadioButton and set the listener.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
res = inflater.inflate(R.layout.rowview, null);
RadioButton radioButton = (TextView)res.findViewById(R.id.radio_view);
radioButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
}
});
}
R.layout.rowview is the view for a single Row in you list view. R.id.radio_view is the id for your radio button within
Upvotes: 2