I added a few buttons with the following lines:
for (int i=0; i<XML.size(); i++) {
ToggleButton b = new ToggleButton(this);
lefttextv.setLayoutParams(lleft);
b.setLayoutParams(bright);
b.setOnClickListener(this);
b.setId(id_button);
System.out.println(id_button);
b.setHeight(100);
b.setWidth(200);
layouth.addView(lefttextv);
layouth.addView(b);
id_button++;
}
But how can I get the OnClick () methods for them? I have already implemented View.OnClickListener using this method:
@Override
public void onClick(View v) {
switch (v.getId())
{
case id_button: Log.d("Button 0","Button 0 pressed);
break;
}
}
But this does not work, how do I get the identifier?
source
share