小编Shr*_*uti的帖子

从微调器中删除最后一项会删除整个列表

我试图使用一个微调控件,使用户可以删除任何列表元素.我有一个"添加"按钮,用于向列表中添加元素,还有一个"删除"按钮,用于从列表中删除当前显示的项目.

除非用户删除列表中的最后一项,否则它将按预期工作.此时,所有列表的项目都将被删除.

我的代码如下:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

    // grab our UI elements so we can manipulate them (for the Spinner)
    // or add listeners to them (in the case of the buttons)
    m_myDynamicSpinner = (Spinner)findViewById(R.id.dynamicSpinner);
    m_addItemText = (EditText)findViewById(R.id.newSpinnerItemText);
    Button addButton = (Button)findViewById(R.id.AddBtn);
    Button clearButton = (Button)findViewById(R.id.ClearBtn);

    // create an arrayAdapter an assign it to the spinner
    m_adapterForSpinner = new ArrayAdapter(this, android.R.layout.simple_spinner_item);
        ((ArrayAdapter)m_adapterForSpinner).setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    m_myDynamicSpinner.setAdapter(m_adapterForSpinner);

    // add listener for addButton
    addButton.setOnClickListener(new OnClickListener() {
        @Override
        public …
Run Code Online (Sandbox Code Playgroud)

android spinner

5
推荐指数
1
解决办法
1492
查看次数

标签 统计

android ×1

spinner ×1