dynamic add data to spinner but not update the data on the spinner

后端 未结 3 652
日久生厌
日久生厌 2021-01-26 16:45
 public class testAddSpiner extends Activity {
private Spinner m_myDynamicSpinner;
private EditText m_addItemText;
private ArrayAdapter m_adapterForS         


        
相关标签:
3条回答
  • 2021-01-26 16:53
    addButton.setOnClickListener(new OnClickListener(){
    
            @Override
            public void onClick(View v) {               
                addNewSpinnerItem();
              int a=  m_adapterForSpinner.getCount();
                m_myDynamicSpinner.setSelection(a-1);
    
               // m_adapterForSpinner.notifyDataSetChanged();
            }                   
        });
    
    0 讨论(0)
  • 2021-01-26 17:05

    Try to call notifyDataSetChanged() after adding an item to adapter:

    private void addNewSpinnerItem() {
        CharSequence textHolder = "" + m_addItemText.getText();
        m_adapterForSpinner.add(textHolder);
        m_adapterForSpinner.notifyDataSetChanged();
    
    }
    
    0 讨论(0)
  • 2021-01-26 17:06

    Have you tried to select the first item? spinner.setSelection(0);?

    0 讨论(0)
提交回复
热议问题