Friday 15 July 2011

java - Android - Scroll to position in ListView in ListFragment after data of adapter has changed -


I'm using a ListFragment with a custom adapter, which sequences to be blown

My problem is now that I want to scroll a certain position (to show the previous scroll) element, that is, when I select an element, the piece is destroyed Goes and wants to show the same place in the list after the fragment is displayed again I am here.

To create the scene and everything works fine, but I do not know how to add getListView (). SetSelection (x) line to scroll to a certain position. I'll call it the loader & lt ;? & Gt; .onLoadFinished () after clearing the elements in the adapter function and add try to invite it, but it does not work, I get the following exceptoins:

  java. Lang.IllegalStateException: Content view is not yet made on Android. fs.pokemon.effect.PokemonFragment.updateData (PokemonFragment.java) on Support.v4.app.ListFragment.ensureList (ListFragment.java:328) android.support.v4.app.ListFragment.getListView (ListFragment. Java: 222), on fs.pokemon.effect.PokemonFragment $ 2.onLoadFinished (PokemonFragment.java:129) ...   

My question is this: is there any function / callback, so advised me Is when the listing view has updated its content? Or how can I scroll the view in a situation after loading the content? Thanks for writing the comment I tried to redo it and saw that the exception is

SetSelection () does not occur in but rather in getListView () - although the data is loaded after loading my view, but instead it uses cached results. So, onLoadFinished () was actually said before the closing of the scene to start Before the end, there would be an exception in this way.

This is to set the position in onLoadFinished () and then override the piece onViewCreated () and execute getListView () . SetSelection there.

Perhaps even in that case the loader cleaned its cache and called onLoadFinished () after the onViewCreated () method, but So far it works fine. L

No comments:

Post a Comment