I want do a app with a class to create buttons dynamically with a for loop.
I call the constructor AND the click listener.
All code except the click listener goes, that does not change the activity that I have, I can do?
public BotonPersonalizado(RelativeLayout layoutactual, int id, int posicionX,
int posicionY, String texto, final Context contexto) {
Button boton = new Button(contexto);
boton.setId(id);
boton.setText(texto);
boton.setTextSize(10);
boton.setMinimumHeight(5);
boton.setHeight(5);
boton.setWidth(100);
boton.setX(posicionX);
boton.setY(posicionY);
boton.setTextColor(Color.BLACK);
layoutactual.addView(boton);
I use the context to change and use Intent.FLAG_ACTIVITY_NEW_TASK for call a new activity
boton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int pasarid = v.getId();
Intent i = new Intent(contexto,Tercero.class);
i.putExtra("id", pasarid);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
contexto.startActivity(i);
}
});
}