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
Related
Is there a JavaFX equivalent to the Android SDK's listview where you can customize the items to have a specific layout using xml?
For instance in Android, if every item needs to have two text boxes for two separate properties, you can make a custom ArrayAdapter and populate the listview using that.
As far as I know, the ListView in FX isn't built for that.
Thanks in advance
I'm trying to make a android app with a scrollable list like this one...
When I made this app in iOS, I used a UICollectionView. What`s the best way to make this in android studios?
I tried using a list view, but I can't seem to customize it to my needs?
Any Ideas?
ListView was a great way to start and it is customizable to your needs.
However I would recommend to use RecyclerView which works almost on the same principle as ListView but it is a newer concept in Android. It handles the usage of the ViewHolder pattern for you which makes everything super easy.(With ListView, you would've had to implement your own ViewHolder pattern)
All you need to do is to have the RecyclerView in your activity/fragment as the view to hold your data. Then, the key component is to implement the RecyclerView's Adapter which will handle the inflation and setup of each list item.
Here is a really great and short tutorial to get you started with RecyclerView.
If you're done with that here is a bit more advanced video material on RecyclerView from Dave Smith explaining a lot of ways on how to understand and use RecyclerView in your apps.
A ListView fed by an ArrayAdapter of custom objects can do the job.
You might have a class that contains the text and the image of a single item.
Then you can create an ArrayList with items of that class, where you put in all the data.
This ArrayList can be used as dataset for a custom ArrayAdapter, which overrides the getView()-method.
The getView()-method must inflate the xml-layout for each item and attach the data from the ArrayList to the inflated view.
You might want to implement the Viewholder-pattern to achieve a good performance and avoid unnecessary inflations and getViewByID()-calls.
You can also use the new CardView, which can make it a lot easier, since it is made for the new material design in android 5, which looks similar to your item list.
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.
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
I'm developing an app on Honeycomb with a ListView. When using a normal ArrayAdapter to feed the ListView content, I can pass it a built-in layout such as Android.R.layout.simple_selectable_list_item. This creates a clickable item with a nice fading animation when selecting an item that is consistent with the overall Honeycomb feel.
However, if I decide to use my own custom layout (or to create a custom adapter), I no longer have any animation when focusing on or selecting an item in the ListView. I could construct my own animation, but I would prefer to use the default Holo theme when developing for Honeycomb for simplicity and consistency.
I'm at a loss for how to do this and haven't been able to find anyone else with my struggle (perhaps I'm searching the wrong terms, or am missing something obvious!). Does anyone have any suggestions? I figure it involves identifying some sort of style or theme in the XML file for the layout, but I haven't figured out where to put that or what the contents might be.
Thanks!
Got it: I had to remove all references to android:listSelector and android:background for my ListView. Then I added
android:background=?android:attr/listChoiceBackgroundIndicator
to my top-level view for the ListView row layout.