Reputation:
I have a ListView which contains number of TextViews and a custom footer border. I want the last line of the ListView gone.
I have tried something like this:
if (position == arrayList.size() - 1) {
viewHolder.lineSeperator.setVisibility(View.GONE);
}
It is working but when I scroll the ListView, the line position is changed and mismatched. How do I fix that?
<ListView
android:id="@+id/listRow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/imgFooter"
android:layout_below="@+id/linearRow"
android:divider="@null"
android:listSelector="@android:color/transparent"
android:overScrollMode="never"
android:scrollbars="none"
tools:listitem="@layout/my_row" />
<LinearLayout
android:id="@+id/linearRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/imgProfile"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_20"
android:layout_marginTop="@dimen/margin_10"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.example.ui.widget.TextView
android:id="@+id/txtName"
style="@style/TextViewStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="false"
customFont:fontTextStyle="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.example.ui.widget.TextView
android:id="@+id/txtType"
style="@style/TextViewStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="false"
customFont:fontTextStyle="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.example.ui.widget.TextView
android:id="@+id/txtManager"
style="@style/TextViewStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="false"
customFont:fontTextStyle="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.example.ui.widget.TextView
android:id="@+id/txtLocation"
style="@style/TextViewStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="false"
customFont:fontTextStyle="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.mawthouq.ui.widget.CustomTextView
android:id="@+id/txtTotalRow"
style="@style/TextViewStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="false"
customFont:fontTextStyle="1" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<View
android:id="@+id/lineSeperator"
android:layout_width="match_parent"
android:layout_height="@dimen/divider_height"
android:layout_below="@+id/linearRow"
android:layout_marginLeft="@dimen/margin_20"
android:layout_marginRight="@dimen/margin_20"
android:layout_marginTop="@dimen/margin_10"
android:background="@color/divider_color" />
Upvotes: 1
Views: 238
Reputation: 4345
get Last Position in an ArrayList using,
int LastPos = arrayList.size() - 1;
then put,
if (position == LastPos) {
viewHolder.lineSeperator.setVisibility(View.GONE);
}
else
{
viewHolder.lineSeperator.setVisibility(View.VISIBLE);
}
to your Adapter Class.
Upvotes: 0
Reputation: 946
You might need to add the else case, try this and see if it works:
if (position == arrayList.size() - 1) {
viewHolder.lineSeperator.setVisibility(View.GONE);
}else{
viewHolder.lineSeperator.setVisibility(View.VISIBLE);
}
Upvotes: 2