FastScrolling ListView with Xamarin.Forms - android

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

Related

Broken inheritance hierarchy when using Pixate within Xamarin.Android app

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.

Android Open ListView from another ListView without intents

I searched allover but couldn't find any clear answer. I have a ListView declared in A customView and I would like to open another ListView when clicking on an Item.
I managed to do that by changing the adapter each time I click on an item on the Main ListView and show a pseudo new ListView. However this is not a stable solution.
I would like to know how can I instantiate a new listView without using intents or without having to change the adapter each time I want a new list output. I would want to create an entirely new ListView without direct connection to the initial one.
Can you try using ListFragment with FrameLayout in layout file? and just switch fragment when click on list item
I found the solution. I created in the CustomView several LinearLayouts for each listview one root layout. I have also created an individual class for each listView and used the same CustomAdapter and ViewHolder throughout. What I additionally used were interfaces that I declared in each List View class, with a method that tracks the row number. Based on this I implemented all the interfaces in the CustomView and listened to the clicked rows. At last, I then created animation methods and played with the visibilities.
By the way, instead of setting the List views to INVISIBLE i set them to GONE, hence there are quite manny the GPU doesn't need to recalculate the layout bounds.
Hope that helps cheers.
The method that i Place in the customView init() looks like this:
The interface listener must be implemented on "this" context of the CustomView, otherwise NUllPointerException hence the ListView doesn't know where to listen too.

Listview fillup with adatper

I have created custom listview with baseadapter.
it's working fine.
but I am calculating total amout when adatper is filliup via getview method.
My question is when I can find that adapter has completed his process of filling up listview?
When adapter called getview() method for last the record after that I want to broadcast message. How can I do?
Thanks.
Adapter does not fill listview completely. It will only fill views that are on the screen ( it also depends on framework cos companies like Samsung, Sony do change the android framework a lot)
The best you should do is call Notifydatasetchanged on adapter and then handle call after that.
Views and whatever adapter needs to call should be done by then
Can you please explain more what you want to achieve. You probably need to use the adapter data and not think about touching its UI part?

Is it okay to change a ListView's adapter dynamically?

Instead of creating multiple activities, I would like to change the ArrayAdapter of the ListView as needed. I don't see any mention in the API about whether or not it is okay to call setAdapter() more than once.
To be more specific, say I would like to start an activity that has a ListView. In this example, the ListView is initialized with a listView.setAdapter(this) from, say, a CategoryArrayAdapter.
Then a user selects a category. Without starting a new activity, the code will set a new adapter for the same ListView. The new adapter, say ItemArrayAdapter calls listView.setAdapter(this).
Does someone have experience having done this successfully or know of a specific reason why this shouldn't be done?
I don't see any mention in the API about whether or not it is okay to call setAdapter() more than once.
The simple answer is YES, and I have done similar sort of things before.
This is exactly the reason why Adapter is existed and provided in the API. The actual content (Model) and how it is rendered (View) for each list items is isolated and implemented inside android.widget.Adapter, instead of directly bound to android.widget.AdapterView. As long as your adapter is properly implemented, you can swap/change the actual underlying adapter that bound to the ListView, simply by calling the setAdapter() method.
Resetting the adapter is ok, but notice, that there might be a GUI glitch when doing so, as the view whose adapter is being changed has to be redrawn with the new data. Aside from this you should be fine.

Android set elements of listview cell WITHOUT custom listview adapter

I want to do something like mylistview.setElementsofView(0).getElementById.setColor("black");
currently the only way I know of doing this is setting up a custom list view adapter, setting up constructors, do conditional checks to see if view is populated, then do stuff in that view
this seems very convoluted, when other parts of the listview are so easily accessible.
is there some inherited function I can access in listview to allow me to access the elements of a particular view without a custom adapter?
Thanks for any insight
The short answer to your question:
is there some inherited function I can access in listview to allow me to access the elements of a particular view without a custom adapter?
unfortunately is no.
Why do you think setting up a custom adapter is so convoluted? Just make the customized adapter class a nested class within your activity. Most likely, you'd only be looking at overriding the getView() method. In the end, you'll spend a lot less time doing this than looking for a "simple" solution.
What about
myListView.getChild(index).setColor("black");

Categories

Resources