2023-08-17 10:46:24 +02:00
|
|
|
package android.widget;
|
|
|
|
|
|
2024-08-29 13:56:58 +02:00
|
|
|
import java.util.ArrayList;
|
2023-08-17 10:46:24 +02:00
|
|
|
import android.content.Context;
|
2024-02-17 15:15:05 +01:00
|
|
|
import android.graphics.drawable.Drawable;
|
2023-08-17 10:46:24 +02:00
|
|
|
import android.util.AttributeSet;
|
2024-03-16 12:49:28 +01:00
|
|
|
import android.view.View;
|
2023-08-17 10:46:24 +02:00
|
|
|
|
2023-09-12 23:18:47 +02:00
|
|
|
public class ListView extends AbsListView {
|
2023-08-17 10:46:24 +02:00
|
|
|
|
2024-08-29 13:56:58 +02:00
|
|
|
static class FixedViewInfo {
|
|
|
|
|
public View view;
|
|
|
|
|
public Object data;
|
|
|
|
|
public boolean isSelectable;
|
|
|
|
|
|
|
|
|
|
public FixedViewInfo(View view, Object data, boolean isSelectable) {
|
|
|
|
|
this.view = view;
|
|
|
|
|
this.data = data;
|
|
|
|
|
this.isSelectable = isSelectable;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ArrayList<FixedViewInfo> headerViews = new ArrayList<FixedViewInfo>();
|
|
|
|
|
private ArrayList<FixedViewInfo> footerViews = new ArrayList<FixedViewInfo>();
|
|
|
|
|
|
2023-08-17 10:46:24 +02:00
|
|
|
public ListView(Context context) {
|
|
|
|
|
super(context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ListView(Context context, AttributeSet attributeSet) {
|
|
|
|
|
super(context, attributeSet);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-29 13:56:58 +02:00
|
|
|
public ListView(Context context, AttributeSet attributeSet, int defStyleAttr) {
|
|
|
|
|
super(context, attributeSet, defStyleAttr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setAdapter(ListAdapter adapter) {
|
|
|
|
|
if (getHeaderViewsCount() > 0 || getFooterViewsCount() > 0) {
|
|
|
|
|
adapter = new HeaderViewListAdapter(headerViews, footerViews, adapter);
|
|
|
|
|
}
|
|
|
|
|
super.setAdapter(adapter);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-17 15:15:05 +01:00
|
|
|
public int getDividerHeight() {return 0;}
|
|
|
|
|
|
|
|
|
|
public Drawable getDivider() {return null;}
|
|
|
|
|
|
2024-03-07 15:47:10 +01:00
|
|
|
public void setTextFilterEnabled(boolean enabled) {}
|
|
|
|
|
|
2024-08-29 13:56:58 +02:00
|
|
|
public void addHeaderView(View v, Object data, boolean isSelectable) {
|
|
|
|
|
headerViews.add(new FixedViewInfo(v, data, isSelectable));
|
|
|
|
|
if (getAdapter() instanceof HeaderViewListAdapter) {
|
|
|
|
|
observer.onChanged();
|
|
|
|
|
} else if (getAdapter() != null) {
|
|
|
|
|
setAdapter(getAdapter());
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-16 12:49:28 +01:00
|
|
|
|
2024-04-12 18:32:30 +02:00
|
|
|
public void setDrawSelectorOnTop(boolean dummy) {}
|
|
|
|
|
|
2024-08-29 13:56:58 +02:00
|
|
|
public void addHeaderView(View view) {
|
|
|
|
|
addHeaderView(view, null, true);
|
|
|
|
|
}
|
2024-04-12 18:32:30 +02:00
|
|
|
|
2024-08-29 13:56:58 +02:00
|
|
|
public boolean removeHeaderView(View view) {
|
|
|
|
|
boolean result = false;
|
|
|
|
|
if (getAdapter() instanceof HeaderViewListAdapter)
|
|
|
|
|
result = ((HeaderViewListAdapter)getAdapter()).removeHeader(view);
|
|
|
|
|
if (result)
|
|
|
|
|
observer.onChanged();
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2024-04-12 18:32:30 +02:00
|
|
|
|
|
|
|
|
public int getHeaderViewsCount() {
|
2024-08-29 13:56:58 +02:00
|
|
|
return headerViews.size();
|
2024-04-12 18:32:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getFooterViewsCount() {
|
2024-08-29 13:56:58 +02:00
|
|
|
return footerViews.size();
|
2024-04-12 18:32:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setDivider(Drawable drawable) {}
|
2024-06-28 22:31:47 +02:00
|
|
|
|
|
|
|
|
public void setSelectionFromTop(int position, int y) {}
|
2024-08-25 11:20:01 +02:00
|
|
|
|
2024-08-29 13:56:58 +02:00
|
|
|
public void addFooterView(View v, Object data, boolean isSelectable) {
|
|
|
|
|
footerViews.add(new FixedViewInfo(v, data, isSelectable));
|
|
|
|
|
if (getAdapter() instanceof HeaderViewListAdapter) {
|
|
|
|
|
observer.onChanged();
|
|
|
|
|
} else if (getAdapter() != null) {
|
|
|
|
|
setAdapter(getAdapter());
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-25 11:20:01 +02:00
|
|
|
|
2024-08-29 13:56:58 +02:00
|
|
|
public void addFooterView(View v) {
|
|
|
|
|
addFooterView(v, null, true);
|
|
|
|
|
}
|
2024-08-25 11:20:01 +02:00
|
|
|
|
|
|
|
|
public void setDividerHeight(int height) {}
|
2024-09-03 17:51:25 +02:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setSelection(int position, boolean animate) {
|
|
|
|
|
super.setSelection(position + getHeaderViewsCount(), animate);
|
|
|
|
|
}
|
2023-08-17 10:46:24 +02:00
|
|
|
}
|