I'm trying to add Pixate to our cross-platform app built with Xamarin.
In Android app I'm using custom ListView and custom adapter which implements an interface. But when the Adapter property of the list view is being set to my custom adapter its base class is Java.Lang.Object instead of BaseAdapter and does not implement the interface anymore (cast will cause an exception).
Anyone had a similar issue with Pixate ? How do I fix it ?
I've answered to this one on the github repo, so here is a copy-paste of that.
Pixate work on AdapterViews by proxying them in order to tag the recycled views with their new position (see https://github.com/Pixate/pixate-freestyle-android/blob/master/pixate-freestyle/src/com/pixate/freestyle/PXHierarchyListener.java#L232 ). This allows us to style more complex CSS expressions, like "nth-child" on a list.
Currently, that java.lang.reflect.Proxy is being created with a few known adapter interfaces, so the casting will fail if you would like to get your original BaseAdapter.
The good news is that we have a way to get to that original Adapter via PixateFreestyle.getAdapter(AdapterView view). Then you can cast to your BaseAdapter. That should not cause any problem.
Related
I am new to android and learning about the adapters. For this i am using the Android official documentation.
I am confused about one thing regarding adapters. Is the Adapter is super interface of all the adapters classes in android?
If yes then why this is not mentioned on this page that it is super interface of all the adapters in android. In fact it is on the top of hierarchy. See picture below:
and even this interface is also not in the hierarchy here: See picture below:
If no then how the methods of Adapter interface are implemented?
Or may be my understandings are wrong. Is this interface available to be implemented by custom user defined class or no it is implemented internally, or something else? Thank you very much in advance for the explanation and clarification of this confusion.
Is the Adapter is super interface of all the adapters classes in android?
No. It is for the classic AdapterView family of views (e.g., ListView, Spinner) and its set of adapters. RecyclerView.Adapter, PagerAdapter, etc. are unrelated to Adapter, other than they all fill the same sort of role.
and even this interface is also not in the hierarchy here: See picture below:
ArrayAdapter implements ThemedSpinnerAdapter, which extends Adapter. The JavaDocs do not point out the inheritance hierarchy of implemented interfaces.
I would like to have my Xamarin.Forms ListView (XAML) FastScroll.
I already wrote a CustomRenderer for Android and set Control.FastScrollEnabled = true;. But unfortunately this is not enough to make it work. As described here the Adapter needs to implement ISectionIndexer.
In my case the Adapter on the ListView does not (HeaderViewListAdapter).
Does anyone have an Idea how this problem can be solved? I already tried to write a wrapper for the Adapter, but can't get it work (gets never called because I think a ListView's Adapter can not be switched after it has been set once).
Thanks!
Ok, I was able to get it working. I had to create a CustomView in XF that inherits ListView. And in a CustomRenderer I was able to create a new Adapter that implements ISectionIndexer
I'm having a difficult time creating a ListView using a custom class and a custom layout to visualise data. Creating a custom Adapter extending BaseAdapter doesn't seem to be capable of being updated with new data, and I haven't found any examples of using a custom ArrayAdapter that isn't based around simple data types. Any suggestions what should I do?
As long as you call notifyDataSetChanged() on BaseAdapter, there should be no problem updating your custom views with new data. I have used ListViews and RecyclerViews with custom views no problem using custom adapters.
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 am trying to implement a grouped listview on Android similar to iOS. Therefore, I am trying to write my own custom MvxAdapter that supports grouped section headers. The default MvxListView constructed from axml will create a default MvxAdapter. Since I need to supply my own custom MvxAdapter, I need to create the MvxListview programmatically so I can pass in my own adapter. The problem I am having is at the time of OnCreate of my android view where I try to construct my custom MvxAdapter, the Android binding context is null as retrieved from
MvxAndroidBindingContextHelpers.Current()
Is there an example of constructing an MvxListView programmatically with a custom MvxAdapter with v3 API?
There's no examples of creating an MvxListView programatically - almost all Android UI controls are created in axml in the current samples.
For creating custom adapters, there are a few examples around, inclduing:
an example in the polymorphic list in the collection at: https://github.com/slodge/MvvmCross-Tutorials/tree/master/Working%20With%20Collections
an advanced example in the https://github.com/slodge/MvvmCross-Tutorials/blob/master/Sample%20-%20CirriousConference/Cirrious.Conference.UI.Droid/Views/SessionsLists/BaseSessionListView.cs
Alternatively, you can, of course, inherit a CustomListView from MvxListView and can then pass in your custom adapter as part of the constructor.
For more on creating and using custom views, see http://slodge.blogspot.co.uk/2013/05/n18-android-custom-controls-n1-days-of.html
In the event that you ever do want to push a context onto the stack you can do this using:
using (new MvxBindingContextStackRegistration<IMvxAndroidBindingContext>(**TheContext**))
{
// create your controls here
}
This is exactly what happens during xaml inflation - see: https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Binding.Droid/BindingContext/MvxAndroidBindingContext.cs#L47