Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>OK. I have an answer now. The problem being that .setSelectionFromTop() would only work if the listview was in the top layout (ie. not nested). Afters some head scratching I realised that I could make my layout a RelativeLayout and get the same look but without having to nest layouts for the checkbox and listview. This is the new layout:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/recordViewLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"&gt; &lt;CheckBox android:id="@+id/checkBoxTop" android:text="Check All" android:layout_width="160dp" android:layout_height="wrap_content"/&gt;" &lt;ListView android:id="@+id/engNameList" android:layout_width="160dp" android:layout_height="wrap_content" android:layout_below="@+id/checkBoxTop"/&gt; &lt;HorizontalScrollView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@+id/checkBoxTop"&gt; &lt;LinearLayout android:id="@+id/scroll" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"&gt; &lt;include layout="@layout/record_view_line" android:id="@+id/titleLine" /&gt; &lt;ListView android:id="@android:id/list" android:layout_height="wrap_content" android:layout_width="match_parent"/&gt; &lt;/LinearLayout&gt; &lt;/HorizontalScrollView&gt; &lt;/RelativeLayout&gt; </code></pre> <p>This basically is the code that goes with the layout.</p> <p>In onCreate()</p> <pre><code> engListView=getListView(); engListView.setOnTouchListener(this); recordListView=(ListView)findViewById(R.id.recordList); recordListView.setOnScrollListener(this); </code></pre> <p>and the listener methods:</p> <pre><code>public boolean onTouch(View arg0, MotionEvent event) { recordListView.dispatchTouchEvent(event); return false; } public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { View v=view.getChildAt(0); if(v != null) engListView.setSelectionFromTop(firstVisibleItem, v.getTop()); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload