Update a spinner in Android

2019-08-23 22:54发布

问题:

In my application I have 1 spinner option. In that I am displaying 6 values (which is array from values file). Now in that when I click its 5 items of the spinner value the selected item will show in the spinner in the activity screen.

When I select 6th item in spinner I have to start a new activity. Is it possible? Do I have to do this by position value?

Also in the new activity (after selecting 6th item) I have 5 edittext values in which user can enter a string which should replace the old value in the spinner. Is it possible to dynamically update the spinner?

My spinner code:

Spinner s2=(Spinner)findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> adapter1 = ArrayAdapter.createFromResource(
  this, R.array.group_array, android.R.layout.simple_spinner_item);
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s2.setAdapter(adapter1);     

回答1:

It's possible

Codings:

ArrayAdapter yearadp =  new ArrayAdapter(this,android.R.layout.simple_spinner_item,  yearlist);
            yearadp.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

         year_spinner.setAdapter(yearadp);
    index=0;

     year_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
          spintext=parent.getItemAtPosition(pos).toString();

                if(spintext=="6")
                {
 intent        =    new Intent(ListMonthActivity.this,NewChart.class);
 startActivity(intent);
 }
  }
    }

Ya we can do with setting with

mon_spinner.setSelection(iSelectedMonth);
intent        =    new Intent(ListMonthActivity.this,NewChart.class);

You may or not mention while the action are certain action finished, and you can passed into another activity .