Android: Spinner setPadding not work - android

I use this code for set padding to spinner ( not for children )
Spinner spnCategory = (Spinner) findViewById(R.id.spnCategory);
List<String> list = new ArrayList<String>();
list.add("UP");
list.add("Down");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);
dataAdapter.setDropDownViewResource(R.layout.dropdown_item);
spnCategory.setPadding(15, 5, 2, 4);
spnCategory.setAdapter(dataAdapter);
But this code not work

Try removing dataAdapter.setDropDownViewResource(R.layout.dropdown_item);, it should work fine

Related

How to set string from sqlite to Spinner in Android?

I have Spinner in my app and set String[] programmatic.
speciality = (Spinner) findViewById(R.id.general_specality_s);
specialityadapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, speciality_list);
speciality.setAdapter(specialityadapter);
and get selected string like this speciality.getSelectedItem().toString(); and store in sqlite. Now I want to get that value from sqlite and need to set in Spinner1.
String SpinnerText=c.getString(c.getColumnIndex("speciality"));
How to set this string to speciality / Spinner ? Thanks in advance.
Fetch your data into an array and use an array adapter
String[] spinnerArray = your data goes here;
Spinner spinner = (Spinner)findViewById(R.id.yourspinnerid);
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, spinnerArray);
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(spinnerAdapter);

Spinner not showing dropdown view

I am stuck with this issues.
I am using Spinner for showing different languages.But it is opening as a POP UP and i need to open it as dropdwon.
I don't want to use spinnerMode property of XML.
ArrayList<String> array = new ArrayList<String>();
array.add("None");
array.add("Site Visit");
array.add("Order");
array.add("Meeting");
array.add("Send Quotation");
ArrayAdapter<String> sadapter;
sadapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item,array);
spinRequestAction.setAdapter(sadapter);
This way you can make adapter for your spinner.
Here is a sample code
String[] city_list = new String[3];
city_list[0] = "New York";
city_list[1] = "San Francisco";
city_list[2] = "Washington DC";
ArrayAdapter<String> aa=new ArrayAdapter<String> (getApplicationContext(),        
R.layout.spinner_item, city_list);
city_spinner = (Spinner) findViewById(R.id.spinner1);
city_spinner.setAdapter(aa);
for additional help, you can refer here..

Spinner and HTML select

I have spinner for displaying categories. ((String)categorySpinner.getSelectedItem())) gives the category name.
The spinner is initialized as given below:
List<String> list = new ArrayList<String>();
for (int i = 0; i < category.length; i++) {
list.add(category[i].getName());
}
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, list);
dataAdapter.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item
);
shoppingItemCategorySpnr.setAdapter(dataAdapter);
Is there any idea to make spinner like HTML select-tag so that I can display category name and get category id?

Using Multiple Spinners, But Only One Spinner Has All The Data

I have two spinners and two arrays. However, one spinner receives both arrays while the other receives no values from either of the two arrays. Note: I do not want to use radio buttons as the data is shortened for review.
final ArrayList<String> serialnums = new ArrayList<String>();
serialnums.add("576798");
serialnums.add("495874");
serialnums.add("345667");
serialnums.add("956345");
final ArrayList<String> carrys = new ArrayList<String>();
serialnums.add("R");
serialnums.add("L");
serialnums.add("F");
serialnums.add("B");
s1 = (Spinner) findViewById(R.id.spinnerSerial);
spinnerCarry = (Spinner) findViewById(R.id.spinnerCarry);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, serialnums );
ArrayAdapter<String> adapterCarrys = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, carrys );
s1.setAdapter(adapter);
spinnerCarry.setAdapter(adapterCarrys);
Note 2: Spinner s1 gets all the data
One spinner has all the data because you are assigning all the data to it. Change this:
final ArrayList<String> carrys = new ArrayList<String>();
serialnums.add("R");
serialnums.add("L");
serialnums.add("F");
serialnums.add("B");
to this:
final ArrayList<String> carrys = new ArrayList<String>();
carrys.add("R");
carrys.add("L");
carrys.add("F");
carrys.add("B");
You are adding "R" "L" "F" "B" to serialnums add it to carrys

Dynamic spinner options does not open

I have within a TabActivity a Spinner that will be generated dynamically. Just to test, I did so manually:
Spinner sp_departure = (Spinner) findViewById(R.id.spinner_departure);
// This array will be generated through a database
String[] array_spinner = new String[2];
array_spinner[0] = "Departure 1";
array_spinner[1] = "Departure 2";
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, array_spinner);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sp_departure.setAdapter(adapter);
When I run the app looks ok since option selected is "Departure 1" but when I click to open the options I get some errors and the application is closed.
Any idea what could be wrong?
Thanks in advance.
- Update
This is what was generated by LogCat: http://pastebin.com/1QPKZdKB
Yes you might have set setContetView(R.layout.yourxml)...,
Change it to :
View viewToLoad = LayoutInflater.from(this.getParent()).inflate(R.layout.yourxm, null);
this.setContentView(viewToLoad);
and use
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getParent(), android.R.layout.simple_spinner_item, array_spinner);
Try, it may helps you

Categories

Resources