Sto gonfiando un pulsante xml con un pulsante, più volte e sono in grado di farlo perfettamente ma il problema è quando faccio clic sul pulsante, voglio mostrare quale pulsante è stato cliccato.Quando si gonfia dinamicamente un layout xml più volte, come posso differenziare o identificare i widget Button?
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) {
}
}
Sapete che i nomi delle variabili possono e devono essere lunghi più di una lettera. – stimms