Custom Spinner With Buttons - android

I am wanting to create a custom Android spinner such that there are 2 buttons at the bottom of the pop-open list. These buttons will cause another popup. I see two possible methods for creating the buttons. As I am still new to Android I don't know which is better or perhaps there is a third method?
1) In the adapter class, getCustomView() method, return a layout with two buttons in it for the last item in the list. This seems awkward to me. And it pretty much forces me to put the adapter in the view object so that I can control it.
2) Create a totally new custom view object. This seems like a lot of work since the spinner is pretty close to what I need already.
3) ?
I am looking for some expert Android developer opinions. Thanks in advance!

You can go through the following code which I made for custom spinner:
Spinner custom layout keep default layout

Related

How to create custom Spinner?

I am creating a custom Spinner in Xamarin.Android with text and image. I've created the Spinner in Xamarin but don't know how to customise it.
For example how do I create rounded corners and with customised text and image?
Can anyone tell me how to achieve this? I was not able to upload the screen shot of what i have done so far since my reputation is low.
It is done exactly the same way as in Native Android development. You need to implement a custom Adapter to fill the Spinner with Views that live up to your requirement. Such an Adapter handles which View is shown when and at which position. It handles inflating these Views and populating them with the correct data.
As for styling the Spinner, it is done through the Styling system that Android provides. Which is not specific to how Xamarin.Android (or MonoDroid) does it.
You need to look into the documentation about Custom Adapters, read Creating Custom Row Layouts (in this case they are for ListView, but can easily be adapted to Spinner by overriding and implementing the GetDropDownView) and Spinner

Android ListView custom row overlay

I am developing an activity with a ListView in which I need to change the current row by another layout by clicking on the row, and I'm not finding any way to do as much as I look (I take hours searching for possible solutions and I have not seen any reference to this problem). I do not know if this can be done in Android, but if anyone has an idea of ​​how to do this would be appreciated.
Thanks in advance.
PS: The ListView control is normal and just want to replace a layout with a different layout. I'm using the API 15.
Use a ViewSwitcher
http://developer.android.com/reference/android/widget/ViewSwitcher.html
A ViewSwitcher is -
ViewAnimator that switches between two views, and has a factory from
which these views are created. You can either use the factory to
create the views, or add them yourself. A ViewSwitcher can only have
two child views, of which only one is shown at a time.
I suggest merging the two layouts in a single one and hide the second one. In your adapter data you should have a flag or something to indicate which layout to display. When you click a row, toggle that flag for the selected item and notifyDataSetChanged() on the adapter. This will make sure the changed layout remains even if you scroll up and down and the row goes off screen.
A more optimized solution is to have different item types in the adapter.

Android: Creating custom view and adding it to layout dynamically

I want to create a custom view with some text and two buttons all on one line. I need to be able to add multiple (any number) of these views to an existing layout dynamically (needs to be able to scroll). I want to pass a custom object to the view and set the text and buttons. I need access to the button event handlers from the activity. I've looked a little into custom views but I'm still at a loss for how to do what I want. I'm used to .NET custom controls, and I'm looking for the same effect. Any help or example code would be greatly appreciated.
What you want is custom compound view. You should write you own class (usually extending one of the layouts) and whole behavior, inflate the layout the way you want etc.
More of it: http://developer.android.com/guide/topics/ui/custom-components.html
This one helped me a lot too: http://javatechig.com/android/creating-custom-and-compound-views-in-android-tutorial
If you use list activity or list fragment, you will automatically have the many features you have asked for. You only need to create a adapter class for your listview. You can define your layout for your row view(buttons, text etc..) Try to look at the examples on the web for cusom adapter and lists.

ListItem click and checkbox click at the same time

I've been trying many things with list items and i'm facing some problems. In my previous question, thanks to #nEx.Software i was able to resolve the problem. But I'm still missing some concepts here.
Right now i'm trying to differentiate between an item's click and a checkbox within it. However, I want to do it without extending the array adapter. Is there a way to use both methods: listView.onItemClickListener() AND listView.getCheckedItemPositions(), together!
There should be a way to use an xml file [doesn't matter how complex it gets] along with extending the available Views and this thing should be done.
Putting it simple, open the gmail app, and u'll find all emails listed with checkboxes where u can click on the checkbox to mark it OR the rest of the item to open the email.
Again, I know that it is doable with extending Adapters and adding an Array for the checkboxes, but, is it possible to use the convenient methods: listView.onItemClickListener() AND listView.getCheckedItemPositions()? is CheckedTextView a part of the solution?
One more thing, rather than just answering me [where i become lazy]
Wheather it is possible or not, is there a verry reliable reference for such issues? I would really like to fully understand everything that goes into this matter... if its not possible, i must be able to tell why!
Thank you :)
add custom row into your listview. into your custom row you add one textview and checkbox into linerlayout and get linerlayout click event.

How to set up a real custom Listview?

In my app, I should set up a "real" custom listview.
For example :
First line(Some Text) Checkbox
Second line(Some Text) Spinner
What I mean is that each line has different widget. In the example, for the first line, we have a checkbox, for the second, it is a Spinner.
Does someone have any idea of how I can set it up?
Thanks a lot!
Do you really think you need a ListView? Or could a ScrollView fix your problem already?
If you definitely need a ListView, read my answer here: How to add multiple headers throughout a single ListView with addHeaderView()?
You can define different types for your items and return a different layout for each type, while still having the possibility to get higher performance by using convertView.
Check out an example given on this page for defining custom-listview: http://www.androidpeople.com/android-custom-listview-tutorial-example/
Same way, you can define your custom-layout for listview, you just need to implement getView method.

Categories

Resources