Estoy inflando un botón que tiene xml, varias veces y puedo hacerlo perfectamente pero el problema es que cuando hago clic en el botón, quiero mostrar en qué botón se hace clic.Al inflar un diseño xml dinámicamente varias veces, ¿cómo puedo diferenciar o identificar los widgets de botón?
public class InflateExActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
Button b;
LinearLayout lLayout;
LayoutInflater inflater;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
for (int i = 0; i < 3; i++) {
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
b = (Button) inflater.inflate(R.layout.buttons, null);
t = (TextView) inflater.inflate(R.layout.texts, null);
b.setTag(i); // you'll get 0,1,2 as
lLayout = (LinearLayout) findViewById(R.id.layout1);
lLayout.addView(b);
b.setOnClickListener(this);
}
}
public void onClick(View v) {
}
}
Usted sabe que los nombres de variables pueden, y deben ser, de más de una letra de longitud. – stimms