0

我有一个微调器,用户可以在其中动态输入项目。我想当用户从微调器中选择一个项目来开始另一个活动时。

我用:

  ...
  m_myDynamicSpinner = (Spinner)findViewById(R.id.myspinner);
  m_addItemText = (EditText)findViewById(R.id.editTextItem);
  Button addButton = (Button)findViewById(R.id.add);
  Button removeButton = (Button)findViewById(R.id.remove);

  m_adapterForSpinner = new ArrayAdapter(this, android.R.layout.simple_spinner_item);
  m_adapterForSpinner.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  m_myDynamicSpinner.setAdapter(m_adapterForSpinner);
  m_adapterForSpinner.add("Items List");

 ....

  }
 private void addNewSpinnerItem() {
     CharSequence textHolder = "" + m_addItemText.getText();
     m_adapterForSpinner.add(textHolder);
     }

     private void clearSpinnerItems() {
     m_adapterForSpinner.clear();
     m_adapterForSpinner.add("Items List");
     }
     public class MyOnItemSelectedListener implements OnItemSelectedListener {

     public void onItemSelected(AdapterView<?> parent,
     View view, int pos, long id) {

     m_addItemText.setText((CharSequence)parent.getItemAtPosition(pos).toString());

     if (pos == 1){
         Intent intent = new Intent(MainActivity.this, selection.class);
         MainActivity.this.startActivity(intent);
     }

     }

但什么也没发生。

4

1 回答 1

1

将此添加到您的代码中

m_myDynamicSpinner.setOnItemSelectedListener(new MyOnItemSelectedListener());

希望这对您有所帮助。

于 2013-03-19T20:48:16.300 回答