Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add items to the spinner dynamically at first index in android?

I put entries in spinner via XML.

Now i am want to insert a item on first index of spinner by pragmatically.

is it possible?

    ddlParkingType = (Spinner) findViewById(R.id.ddlParkingType);

    TextView tv=new TextView(this);tv.setText("All");
    ArrayAdapter<String>  adapter=(ArrayAdapter<String>)ddlParkingType.getAdapter();
    adapter.add("Alll");
like image 793
Manjeet Brar Avatar asked Jan 09 '23 19:01

Manjeet Brar


1 Answers

Try using ArrayAdapter.insert(T object, int index) as:

adapter.insert("New Value",0);
adapter.notifyDataSetChanged();
like image 56
ρяσѕρєя K Avatar answered Feb 27 '23 23:02

ρяσѕρєя K