:
if(playerList.size() < 10) {
// playerList.add
} else {
// do nothing
}
編集:あなたの間違いはここにある:
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
}
あなたがいない外、onClickListener
内のサイズを確認する必要があります
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
}
}
});
あなたは、配列の代わりに使用して試してみましたがリスト? 'String [] myarray = new String [10];' – Jave
ArrayListはString []より速く&変更可能です。 – Lucifer
ArrayListは確かに配列より高速ではありませんが、特にArrayListは内部配列を使ってデータを格納します。配列ではなくリストを使用する理由は、リストの柔軟性が高まり、機能の一部が削除したいということです。 – Jave