xml - Android ListView :: Scrolling ListView while item is selected causes display problems -
alright, i'm using listview
custom adapter. works fine , dandy...until user selects listview
row , tries scroll.
when user selects row, background color of row changes blue (which good).
but, problems occur when begin scrolling: when scroll past selected row, blue fixes either bottom or top of listview
, depending on way scrolling.
selected row changes color on touch (good)
part of background of selected row fixed top when scrolling down (not good)
part of background of selected row fixed bottom when scrolling (not good)
here source code:
list view i'm populating dynamically
<listview android:id="@+id/tallydatalistview" android:layout_height="wrap_content" android:layout_width="fill_parent" android:divider="#000000" android:dividerheight="1dp" android:fadescrollbars="false" android:listselector="#0099ff" >
layout_list_view_row.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <view android:focusable="false" android:focusableintouchmode="false" style="@style/tablesideborderline" /> <textview android:id="@+id/column_pipe_number" android:layout_height="wrap_content" android:layout_width="0dp" android:layout_weight="1" style="@style/tablecolumn" xmlns:android="http://schemas.android.com/apk/res/android" /> <view android:focusable="false" android:focusableintouchmode="false" style="@style/tablecolumndivider" /> <textview android:id="@+id/column_total_length" android:layout_height="wrap_content" android:layout_width="0dp" android:layout_weight="1" style="@style/tablecolumn" xmlns:android="http://schemas.android.com/apk/res/android" /> <view android:focusable="false" android:focusableintouchmode="false" style="@style/tablecolumndivider" /> <textview android:id="@+id/column_adjusted" android:layout_height="wrap_content" android:layout_width="0dp" android:layout_weight="1" style="@style/tablecolumn" xmlns:android="http://schemas.android.com/apk/res/android" /> <view android:focusable="false" android:focusableintouchmode="false" style="@style/tablesideborderline" /> </linearlayout>
my custom adapter
import android.app.activity; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.arrayadapter; import android.widget.textview; import java.util.arraylist; public class listviewadapter extends arrayadapter<string>{ layoutinflater inflater; private final arraylist<string> adjustedvalues; private final arraylist<string> pipenumbers; private final arraylist<string> totallengthvalues; public listviewadapter(activity pcontext, arraylist<string> ppipenumbers, arraylist<string> ptotallengthvalues, arraylist<string> padjustedvalues) { super(pcontext, r.layout.layout_list_view_row, padjustedvalues); adjustedvalues = padjustedvalues; pipenumbers = ppipenumbers; totallengthvalues = ptotallengthvalues; inflater = pcontext.getlayoutinflater(); } @override public view getview(int pposition, view pview, viewgroup pparent) { view view = inflater.inflate(r.layout.layout_list_view_row, pparent, false); textview col1 = (textview)view.findviewbyid(r.id.column_pipe_number); col1.settext(pipenumbers.get(pposition)); textview col2 = (textview)view.findviewbyid(r.id.column_total_length); col2.settext(totallengthvalues.get(pposition)); textview col3 = (textview)view.findviewbyid(r.id.column_adjusted); col3.settext(adjustedvalues.get(pposition)); return view; } }
keep reference selected row position in adapter,
int selectedpos = -1;
the value -1
when no row selected. , in onitemclicklistener
of listview,update selectedpos
clicked position , call notifydatasetchanged()
on adapter. in getview
method of adapter, check selectedpos
value , highlight row accordingly.
Comments
Post a Comment