Android : Jfeinstein10 Sliding Menu - force scrolling to top after data load

on Wednesday, October 8, 2014


Good morning everybody :)


It's been a long time I read on this place (and I've learned so much, thanks for this!) but the first time I post. I hope you will find my question relevant :) I've browsed all topics concerning Jfeinstein sliding menu before, but I've never seen the subject discussed yet.


So I am using the library jfeinstein10 to create a sliding menu in my android app. The sliding menu starts empty (with only a small icon showing "Loading") and a callback function populates it after querying a webservice.


All works well, except one thing : once I have populated my menu, the sliding menu is scrolled down to the bottom (to my last result) and I can't find a way to scroll it back automatically to the top. So it works good if I don't have many items, but if I get more than 9 results in there, I don't see the first ones anymore and I need to manually scroll back to the top.


I'm initializing the slidingMenu this way (pretty usual I think) within my onCreate() method :



slidingMenu = new SlidingMenu(this);
slidingMenu.setMode(SlidingMenu.LEFT);
slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
slidingMenu.setShadowWidthRes(R.dimen.slidingmenu_shadow_width);
slidingMenu.setShadowDrawable(R.drawable.slidingmenu_shadow);
slidingMenu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
slidingMenu.setAboveOffset(20);
slidingMenu.setFadeDegree(0.35f);
slidingMenu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
slidingMenu.setMenu(R.layout.slidingmenu);


Then later on, in my callback function (receiving JSON), I update it this way, using a method from the fragment to communicate with it:



JSONArray channels = null;

try {
channels = (JSONArray) json.getJSONArray("channels");
}
catch (JSONException e) {
Log.e("JSON_PARSING", "Error during answer parsing from channelList : " + e);
}

SlidingMenuFragment slidingMenuFragment = (SlidingMenuFragment)getFragmentManager().findFragmentById(R.id.slidingmenu);
if(slidingMenuFragment != null) {
slidingMenuFragment.updateMenuChannels(channels);
channelLoaded = true;
}


Inside the updateMenuChannels method, it just adds each element to my sectionItem and then adds this sectionItem to the listViewAdapters. It works fine. However, after this... I'm struggling to place the menu back on top.


I've tried so far :



slidingMenu.scrollTo(0,0); // which does not appear to do anything :p


The same code but in a handler which executes a few second later (In case maybe it would take some time to update... Same result, nothing.



slidingMenu.scrollto(-300,0) // which ruins my activity,
//creating a big white space at the top of the application.


I have also tried several other obscure methods (;o) like computeScroll or other ones, but none of them is the solution. Does anybody has a clue on how to force the scrolling of such a menu to the top ?


Any help much appreciated :)


I wish you all a great day!


0 comments:

Post a Comment