Note that there are some explanatory texts on larger screens.

plurals
  1. PORemove Selected Spinner Item In Android
    primarykey
    data
    text
    <p>I have spinner in my Activity which is set the item from JSON data and when i select any item from spinner and set into the spinner, and i have done all this things properly.But when i want to remove selected item from spinner i got exception:</p> <blockquote> <p>E/AndroidRuntime(1022): java.lang.UnsupportedOperationException"</p> </blockquote> <p>and</p> <blockquote> <p>E/AndroidRuntime(1022):atandroid.widget.ArrayAdapter.remove(ArrayAdapter.java:212)</p> </blockquote> <p>at the code line of </p> <blockquote> <p>E/AndroidRuntime(1022):at com.spinnerdemo.SpinDemo$1.onItemSelected(SpinDemo.java:102)</p> </blockquote> <p>Here is my code:</p> <pre><code>public class SpinDemo extends Activity { private static String strUrl = "http://192.168.1.61/jyoti/android_app/all_questions.php"; private static String TAG_ID = "id"; private static String TAG_CODE = "q_prefix"; private static String TAG_CODE_ARR = "Questions"; JSONArray jsonArray = null; Spinner codeSpinner, spinner2; EditText edTextSpinnerItem; String[] items; String strEdtext; String strid , strcode ; ArrayList&lt;String&gt; codeList; public ArrayAdapter&lt;String&gt; adapter ; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); codeList = new ArrayList&lt;String&gt;(); codeSpinner = (Spinner) findViewById(R.id.spinner2); JSONParser jParser = new JSONParser(); JSONObject json = jParser.getJSONFromUrl(strUrl); try { jsonArray = json.getJSONArray(TAG_CODE_ARR); // looping through All Contacts final String[] items = new String[jsonArray.length()]; for(int i = 0; i &lt; jsonArray.length(); i++) { JSONObject c = jsonArray.getJSONObject(i); // Storing each json item in variable strid = c.getString(TAG_ID); strcode = c.getString(TAG_CODE); items[i] = c.getString(TAG_CODE); System.out.println("Hello events " + items); adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_item,items); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); codeSpinner.setAdapter(adapter); } } catch (JSONException e) { e.printStackTrace(); } codeSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1, int pos, long arg3) { // TODO Auto-generated method stub String anyvariable=String.valueOf(codeSpinner.getSelectedItem()); System.out.println("anyvariable = " + anyvariable); edTextSpinnerItem=(EditText)findViewById(R.id.editText_SpinnerItem); edTextSpinnerItem.setText(anyvariable); System.out.println("edTextSpinnerItem " + edTextSpinnerItem); String t = adapter.getItem(pos); System.out.println("Get The Item Position From Adapter = " + t); adapter.remove(t); adapter.notifyDataSetChanged(); codeSpinner.setAdapter(adapter); //mySpinner.setAdapter(m_adapterForSpinner); //adapter.remove((String)codeSpinner.getSelectedItem()); //adapter.notifyDataSetChanged(); //System.out.println("Item is Removed From The Spinner Drop Dwon List"); } @Override public void onNothingSelected(AdapterView&lt;?&gt; arg0) { // TODO Auto-generated method stub } }); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload