我的微调器有问题。当按下按钮时,我从编辑文本中动态地添加微调器上的项目。按下微调器时,项目会正确显示,但无法进行选择且微调器上没有显示。
这是代码:
final ArrayList<String> players = new ArrayList<String>();
ArrayAdapter<String> adapter = new ArrayAdapter<String> (this, android.R.layout.simple_spinner_dropdown_item, players);
final Spinner spinnerplayers = (Spinner)findViewById(R.id.spinnerplayers);
final ImageButton addbutton = (ImageButton)findViewById(R.id.addbutton);
final EditText editname = (EditText)findViewById(R.id.editname);
final EditText editnum = (EditText)findViewById(R.id.editnum);
addbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
players.add(editname.getText().toString()+ " " + editnum.getText().toString());
editname.setText("");
editnum.setText("");
}
});
spinnerplayers.setAdapter(adapter);
final ImageButton removebutton = (ImageButton)findViewById(R.id.removebutton);
removebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
//players.remove(spinnerplayers.getSelectedItem().toString());
}
});
如果需要,微调器 xml 是:
<Spinner
android:id="@+id/spinnerplayers"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1" />
关于问题出在哪里的任何想法?
提前致谢。