android - Can't scroll to top in listview -


I tried a number of ways to scroll to the top in the list view. But nothing worked out.

This is my code (short version):

  public zero location andom user (last string search) {random chromosomes = new random (random number list); Rondoms adapter = new random adapter (this, random); ListView = (ListView) findViewById (R.id.list); ListView.setAdapter (randomsAdapter); LoadRandomUsers (search); } Private zero loadRandomUsers (string search) {{int i = 0; I & lt; result.size (); i ++) for {randomsList.add (new random (result.get (i) .getAsJsonObject () 0)); } ((Rondoms adapter) Random adapter) .notifyDataSetChanged (); }  

Example:

  Private zero loader randomUsers (string search) {for (int i = 0; i & lt; result.size (); I ++) {Randomslist.add (new random (result.get (i) .getAsJsonObject (), 0)); } ################ Scroll area ################# (Randoms adapters) Rondom's Adapter) .NotifiedDataDataSet (); }  

These are the ones I have specifically set for the scroll area :

  listView.setSelectionAfterHeaderView (); ListView.smoothScrollToPosition (0); ListView.post {New Runnabal} {@Override Public Zero Run () {listView.smoothScrollToPosition (0);}});  

XML:

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; LinearLayout xmlns: android = "Http://schemaskandroidkcom/apk/res/android" android: orientation = "vertical" android: Layout_width = "Fill_parent" Android: Layout_height = "Fill_parent" android: background = "#FFFFFF "& Gt; & Lt; ListView android: id = "@ + id / list" Android: Layout_width = "Fill_parent" Android: Layout_height = "Wrap_content" Android: layout_marginLeft = "4dp" Android: layout_marginRight = "4dp" android: scrollbars = "None" / Gt; & Lt; / LinearLayout & gt;  

More items:

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; LinearLayout xmlns: android = "Http://schemaskandroidkcom/apk/res/android" Android: paddingBottom = "4dp" Android: paddingTop = "4dp" android: orientation = "horizontal" android: Layout_width = "Match_parent" Android: layout_height = "wrap_content" & gt; & Lt; ImageView Android: ID = "@ + ID / Image" Android: Layout_Wind = "64dp" Android: Layout_Hehat = "64dp" Android: src = "@Drawable / Twitter" /> & Lt; LinearLayout Android: layout_width = "0dp" Android: Layout_height = "Wrap_content" Android: layout_weight = "1" android: orientation = "vertical" android: paddingLeft = "4dp" Android: paddingRight = "4dp" & gt; & Lt; TextView android: id = "@ + id / Embed" style = "@ android: style / TextAppearancekMedium" Android: Layout_width = "Match_parent" Android: Layout_height = "Wrap_content" Android: layout_weight = "1" Android: Textcolor = " # 0A4A14 "Android: Layout_Margin =" 8Dp "Android: Text Size =" 15sp "Android: FontFamily =" Without-Serif-Condensation "/> & Lt; TextView android: id = "@ + id / bio" style = "@ android: style / textAppearance.Small" Android: Layout_width = "Match_parent" Android: Layout_height = "Wrap_content" Android: layout_weight = "1" Android: Tekstcolr = " # 474747 "Android: layout_marginLeft =" 8dp "Android: maxLines =" 3 "Android: text size =" 11 SP "Android: layout_margintop =" 0dp "/> & Lt; / LinearLayout & gt; Android: Android: Android: layout_width = "wrap-content" Android: layout_height = "wrap-content" Android: layout_gravity = "right | center_for" Android: src = "@ line / anchor" /> & Lt; Image: Android: ID = "@ + ID / Image 1" & lt; / LinearLayout & gt;  

Why are these ways not working?


Comments