Hey i am creating a spinner dynamically..it creating fine..no problem with that...but items are separate with narrow gap thats why one item is almost attached with others...i want a gap between items.please help
my code is like below..
ArrayAdapter<String> adapter=new ArrayAdapter<String>(BidActivity.this,android.R.layout.simple_spinner_item,result1);
spinner=(Spinner) findViewById(R.id.spinner1);
spinner.setAdapter(adapter);
You need to create a Custom Spinner Layout for this type of achievement.
Go to this Link custom-layout-for-spinner-item used this and customized by your own way.
thnks
my suggestion is please go for a custom spinner for which you can see the code at
http://mrbool.com/how-to-customize-spinner-in-android/28286
http://androidexample.com/Custom_Spinner_With_Image_And_Text_-_Android_Example/index.php?view=article_discription&aid=84&aaid=107
http://www.edureka.in/blog/custom-spinner-in-android/
Related
I just wanna ask how can I create a multi selection spinner in android and the data that will be populated to is from the database. I saw this example here in SO Android Spinner with multiple choice and tried to use it but I don't know what to do next. This is my spinner and adapter and I want to make it in multiselect spinner. Help me please...
spn_CustomerSegment = (Spinner)findViewById(R.id.spn_CustomerSegment);
List<String> ConsumerSeg = databaseHandler.setItemOnConsumerSeg();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(IreportMain.this, android.R.layout.simple_spinner_item, ConsumerSeg);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spn_CustomerSegment.setAdapter(adapter);
I know its not direct answer but you can try using a acrollView (vertical or horizontal) and populate it with checkboxes.
it can give you a nice effect end no extra coding is needed
I am using spinner and looking for other similar control in Eclipse, I need to change drop down view of spinner.
ArrayAdapter<String> Timeadapter = new ArrayAdapter(this,android.R.layout.simple_spinner_item, TimeIntervals);
For this I have used simple_spinner_dropdown_item but it change whole spinner view with a radio button in front
ArrayAdapter<String> Timeadapter = new ArrayAdapter(this,android.R.layout.simple_spinner_dropdown_item, TimeIntervals);
But output view I am looking for is not there.
Please help,
I'm thinking this mihgt help you Multi Selection Dialog and this might be helpful too Single Selection Dialog anyway you can always get help from here, I hope this is useful to you
I have set a dynamic value in a spinner . I am using following code for the same.
spinner_generalbooks.setAdapter(new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_item, new String[]{"Author","ISBN","Keyword","Title"}));
It is working fine, but I have a problem with the view of the spinner . If we select simple_spinner_item, it is ok in normal state, but when we want to change it, the rows are very narrow and not CheckedTextView whereas in normal spinner options comes with CheckedTextView. If we select simple_spinner_dropdown_item, the options come with CheckedTextView, but in normal state, it looks different as in the pic
(First one is default spinner and second one is using simple_spinner_dropdown_item).
I want to show the spinner just like as default spinner. How to make it?
Android will take the layout specified in the adapter and use it for the control and the items unless you specify the view-resource separately. The way through this is to set the layout to simple_item in the ArrayAdapter constructor and then set the layout dropdown_item separately in a call to setDropDownViewResource().
ArrayAdapter newAdapter = new ArrayAdapter(getApplicationContext(), android.R.layout.simple_spinner_item, new String[]{"Author","ISBN","Keyword","Title"});
newAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner_generalbooks.setAdapter(newAdapter);
If you whant to customize the visual of your Spinner, it'll be more simple to create your own component. A spinner is just a Layout that contains text, image and that display a list in a popup. Create a custom layout for your item and use a new BaseAdapter object to bind your datas.
http://thinkandroid.wordpress.com/2010/01/13/custom-baseadapters/
hope i could help
My activity has a spinner and a custom ListView and they are both sourced by custom ArrayAdapters (ArrayList of custom objects). The ListView rows are custom views (just 2 TextViews).
When I include the line, spinner.setAdapter(spinnerArrayAdapter); the ListView is NOT filled with data on the screen and the spinner contains the values I want.
When I remove the line, spinner.setAdapter(spinnerArrayAdapter); the ListView is filled with the data I want and the spinner does NOT contain any values.
When I debug, I see the data in the ListView's custom ArrayAdapter variable and the spinner's custom ArrayAdapter.
I have checked my getView() implementation for the ListView's custom ArrayAdapter class.
Suggestions?
Thanks in advance!
Can you paste some code to help identify the problem. I tested with two listviews and a spinner pointing to the same adapter. It worked fine for me.
I'm running into a problem: when I use a non-trivial type of Spinner item, the Spinner displays the drop-down list someplace other than on the Spinner.
(Note: most of this description is identical to https://stackoverflow.com/questions/4188443/android-doesnt-honor-selection-change-with-custom-spinner-items, but the problem I'm reporting here is slightly different. I've split these up so it's clear where to direct different replies to)
My goal was to have a slightly more fancy display for each item in the spinner, and so I started by creating a layout that contains several items, one of which is the target TextView (lbl2, in this case)
I then attempt to set up the Spinner (my eventual goal is to populate the spinner programmatically, so I'm not using resources to set this up) using:
Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(
this, R.layout.spinner_fancy, R.id.lbl2);
adapter.add("Item #1");
adapter.add("Item #2");
adapter.add("Item #3");
spinner.setAdapter(adapter);
When I run the program it looks (mostly) good - the Spinner is, in fact, rendering the goofy-looking multi-color, vertical layout of three textviews for each item, and it's correctly substituting Item #1, Item #2, and Item #3 for lbl2. I can even click on the spinner & bring up the drop-down list of choices.
This problem is that the items aren't displayed over the spinner. Instead they're just kind of floating over the activity, a bit further down. Hopefully this picture will help clarify: Floating Spinner Elements http://www.freeimagehosting.net/uploads/bf9f584156.png
EDIT: Thanks for the vote up - I've fixed up the image so it's now inline!
Android Spinners work in that way... The list of items is shown in "dialog mode".
You can add a title to the list using this in the XML layout (in the spinner section):
android:prompt="Select a fancy item..."