how to add items to the spinner dynamically in android?

前端 未结 3 984
故里飘歌
故里飘歌 2020-12-05 10:36

how to add items to the spinner dynamically in android?

3条回答
  •  天涯浪人
    2020-12-05 11:08

    Spinner spinner = (Spinner)findViewById(R.id.mySpinner);
    ArrayAdapter spinnerAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, android.R.id.text1);
    spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(spinnerAdapter);
    spinnerAdapter.add("value");
    spinnerAdapter.notifyDataSetChanged();
    

    the above is in case of the array adapter, I believe you know how to populate values with ArrayAdapter .

    How can we do this in case of the SimpleCursorAdapter, i.e if we have 2 spinners and if we select the values of one spinner (that is getting the value from SimpleCursorAdapter) depending on some criteria the other spinner should be filled with values. how can we achieve that?

提交回复
热议问题