if we has a some items in the spinner means (like below) how shall we add extra items while run time
here is code:
String[] Items = {
"Alarm",
"Office",
"Meeting",
"Party",
"Lunch",
"Breakfast",
"Supper",
"Home",
"Private",
"Outdoor",
"Family",
"Friends",
"Others"
};
Spinner s1;
and
s1 = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
this,android.R.layout.simple_spinner_item,Items);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s1.setAdapter(adapter);
s1.setOnItemSelectedListener(new OnItemSelectedListener()
{
public void onItemSelected(AdapterView<?> arg0,
View arg1, int arg2, long arg3)
{
int index = s1.getSelectedItemPosition();
Toast.makeText(getBaseContext(),
"You have selected item : " + Items[index],
Toast.LENGTH_SHORT).show();
if (index==12)
{
EditText edit = (EditText) findViewById(R.id.edittext);
Button add=(Button) findViewById(R.id.add);
edit.setVisibility(View.VISIBLE);
add.setVisibility(View.VISIBLE);
}
else
{
EditText edit = (EditText) findViewById(R.id.edittext);
Button add=(Button) findViewById(R.id.add);
edit.setVisibility(View.GONE);
add.setVisibility(View.GONE);
}
}
public void onNothingSelected(AdapterView<?> arg0) {}
});
}
In it if select the “other” means we ve to add extra items in spinner list..
thank you,
I hope you can detect the case when the user has selected “others”
in that case, add the other values in your Items array and call the function
adapter.notifyDataSetChanged()it should accommodate the changes and you should see the new values in the spinner.try this out and revert.