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.
Related
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
Without going into details, I need to attach a drawable at the bottom of last item in ListView. The limitation is I can only use styles & themes to achieve it. No Java code is allowed. I also can't add any item to the end of the adapter.
How can I do it? All hacks are welcome. Thanks!
Added: Or maybe it's possible to attach footerview to the listview via xml?
The main menu of my app is a list of items that has a very specific look. It has a custom divider and every list element has a custom colour and height. To achieve this is have built a custom ArrayAdapter, but I wonder whether this is really necessary. The buttons in the main menu are always the same, so I wonder what's the better design pattern here. Pure XML or overriding the ArrayAdapter?
You cannot create a "Custom ListView for main menu purely in XML not using a programatically defined custom adapter". ListView requires a ListAdapter, whether you like it or not.
That being said, I would not put "buttons" in a ListView in the first place. Ideally, you would not even have a "main menu of [your] app", but rather would take the user someplace useful when they launch it. If you are sure that you need to have an activity that is a "main menu", use the dashboard pattern: Android Dashboard Pattern
I have a Custom ListView in my application and it has some TextViews inside it to which the styles are provided at run time. When I scroll down the ListView and again scroll up, the styles given previously to the TextView changes to some different style.
Is there any way to prevent this?
I think, putting all the code here will make the page look ugly. So kindly follow these links for code-
MyAdapter.java
CustomListItem.java
Do you use custom Adapter? Maybe it is some issue with incorectly reusing convertView, can you post the code?
Or maybe it is just changing background color? In that case simple:
android:cacheColorHint="#00000000"
in ListView's XML will do the work.
I found a way to fix it. Just set the TextView with some default style in the "Convert View" like
textView.setTextAppearance(context , android.R.style.TextAppearance_Small);
in the ViewHolder constructor and in your method you use to set the elements to default state.
I know that similar questions have already been asked but I do not understand what would be the correct approach of solving the issue, yet.
I would like to change the background color of a ListView row when the user clicks it. However due to Android reusing the row layouts when scrolling, the background color gets repeated for other rows. I am wondering what would be the correct approach of maintaining the original layout for all rows except the one changed programmaticaly and also maintain the changed layout information for that row for scrolling back. I am using a SimpleAdapter which is passed the rows layout's XML.
Regards
Your rows' capabilities within your ListView largely depend on the kind of Adapter you are using. In any Adapter where you manually construct or inflate the View per item, you can change the layout properties per item, as long as you do so within the Adapter. Simply add your background color code to when the item's View is built, and it will work like a charm. If you are not able to do so with the current Adapter, consider extending the current one or using a different adapter.
Note: I haven't placed code directly within this answer because where you add it depends upon your own implementation. For instance, I would add .setBackgroundDrawable() to bindView() in an extended CursorAdapter.
Hope this helps,
FuzzicalLogic