Open FeverCombo3 opened 8 years ago
for the first sticky header. you should new a empty view just like this. on the mehod getHeaderView, return new View(context) can work well
same problem. you can not new a null view or set Visibility Gone to hide header.I can not find a suitable way. I would Appreciate any one who can help.
Can't directly setVisibility to View.GONE to the convertView itself, because it will reserve the height of the header(blank space). Workaround from @andyhaha can be used, but that workaround is bad, because it will re-create a new View object every time called. My workaround is little different, because i setVisibility to View.GONE to each of the child of the convertView individually. Here is the example
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white">
<myApp.ContinuedLineView
android:id="@+id/clv_top"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentTop="true"
android:color="@color/grey_e5e5e5"/>
<TextView
android:id="@+id/tv_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/clv_top"
android:padding="8dp"
android:textColor="@android:color/black"
android:textSize="14sp"/>
<myApp.ContinuedLineView
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@id/tv_header"
android:color="@color/grey_e5e5e5"/>
</RelativeLayout>
@Override
public View getHeaderView(int position, View convertView, ViewGroup parent) {
HeaderViewHolder holder;
if (convertView == null) {
holder = new HeaderViewHolder();
convertView = LayoutInflater.from(getContext()).inflate(R.layout.my_header_layout, parent, false);
holder.text = (TextView) convertView.findViewById(R.id.tv_header);
holder.topLine = (ContinuedLineView) convertView.findViewById(R.id.clv_top);
convertView.setTag(holder);
} else {
holder = (HeaderViewHolder) convertView.getTag();
}
if (getHeaderId(position) == 0) {
holder.topLine.setVisibility(View.GONE);
holder.text.setVisibility(View.GONE);
} else if (getHeaderId(position) == 1) {
holder.text.setText("Some text");
holder.topLine.setVisibility(View.VISIBLE);
holder.text.setVisibility(View.VISIBLE);
} else if (getHeaderId(position) == 2) {
holder.text.setText("Some other text");
holder.topLine.setVisibility(View.VISIBLE);
holder.text.setVisibility(View.VISIBLE);
} else {
holder.text.setText("Undefined Header");
holder.topLine.setVisibility(View.VISIBLE);
holder.text.setVisibility(View.VISIBLE);
}
return convertView;
}
Where ContinuedLineView is my custom view that draw a line
@hendrawd This works perfect! Thank You
In my project,i dont need the first header,i want to hide or delete the first header,how to do it using this library?