Nel vostro metodo del gestore:
if(playerList.size() < 10) {
// playerList.add
} else {
// do nothing
}
Edit: Il tuo errore è qui:
if(playerList.size() < 10) {
Button confirm = (Button) findViewById(R.id.add);
confirm.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
EditText playername = (EditText) findViewById(R.id.userinput);
playerList.add(playername.getText().toString());
adapter.notifyDataSetChanged();
playername.setText("");
}});
} else {
// do nothing
}
Si dovrebbe controllare la dimensione all'interno del onClickListener
, non fuori:
Button confirm = (Button) findViewById(R.id.add);
confirm.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
EditText playername = (EditText) findViewById(R.id.userinput);
if(playerList.size() < 10) {
playerList.add(playername.getText().toString());
adapter.notifyDataSetChanged();
playername.setText("");
} else {
// do nothing
}
}
});
Hai provato a usare una matrice, invece di una lista? 'String [] myarray = new String [10];' – Jave
ArrayList è più veloce e mutabile rispetto a String [] – Lucifer
ArrayList non è certamente più veloce di un array, soprattutto perché ArrayList utilizza un array interno per memorizzare i dati. La ragione per utilizzare le liste piuttosto che gli array è che le liste sono più flessibili, parte delle quali la funzionalità op vuole rimuovere. – Jave