android - Can't scroll to top in listview -
i tried lot of methods scroll top in listview.but nil worked.
this code (shortened version):
public void placerandomusers(final string search) { randoms randoms=new randoms(randomslist); randomsadapter=new randomsadapter(this,randoms); listview = (listview)findviewbyid(r.id.list); listview.setadapter(randomsadapter); loadrandomusers(search); } private void loadrandomusers(string search) { (int i=0; i<result.size(); i++) { randomslist.add(new random(result.get(i).getasjsonobject(),0)); } ((randomsadapter) randomsadapter).notifydatasetchanged(); }
example:
private void loadrandomusers(string search) { (int i=0; i<result.size(); i++) { randomslist.add(new random(result.get(i).getasjsonobject(),0)); } ################scroll area################# ((randomsadapter) randomsadapter).notifydatasetchanged(); }
these placed particularly scroll area
:
listview.setselectionafterheaderview(); listview.smoothscrolltoposition(0); listview.post( new runnable() { @override public void run() { listview.smoothscrolltoposition(0); } });
xml:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff" > <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" /> </linearlayout>
and items:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:paddingbottom="4dp" android:paddingtop="4dp" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"> <imageview android:id="@+id/image" android:layout_width="64dp" android:layout_height="64dp" android:src="@drawable/twitter"/> <linearlayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="vertical" android:paddingleft="4dp" android:paddingright="4dp" > <textview android:id="@+id/tweet" style="@android:style/textappearance.medium" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:textcolor="#0a0a14" android:layout_marginleft="8dp" android:textsize="15sp" android:fontfamily="sans-serif-condensed" /> <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:textcolor="#474747" android:layout_marginleft="8dp" android:maxlines="3" android:textsize="11sp" android:layout_margintop="0dp"/> </linearlayout> <imageview android:id="@+id/image1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right|center_vertical" android:src="@drawable/anchor" /> </linearlayout>
why these methods not working ?
android listview
No comments:
Post a Comment