If you think the Android project GuiLib listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.gandulf.guilib.view;
/*www.java2s.com*/import android.content.Context;
import android.util.AttributeSet;
import android.util.SparseBooleanArray;
import android.widget.AdapterView;
import com.nhaarman.listviewanimations.itemmanipulation.DynamicListView;
publicclass DynamicListViewEx extends DynamicListView {
publicinterface OnItemCheckedListener {
publicvoid onItemChecked(AdapterView<?> list, int position, boolean checked);
}
private OnItemCheckedListener onItemCheckedListener;
public DynamicListViewEx(Context context) {
super(context);
}
public DynamicListViewEx(Context context, AttributeSet attrs) {
super(context, attrs);
}
public DynamicListViewEx(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
/**
* Threadsafe clone for backward compatibility as {@link SparseBooleanArray#clone()} is supported first in 4.x APIs
*
* @param orginal
* @return a clone
*/publicstatic SparseBooleanArray clone(final SparseBooleanArray orginal) {
if (orginal == null)
return null;
final SparseBooleanArray clone = new SparseBooleanArray();
synchronized (orginal) {
finalint size = orginal.size();
for (int i = 0; i < size; i++) {
clone.put(i, orginal.get(i));
}
}
return clone;
}
@Override
publicvoid clearChoices() {
SparseBooleanArray checkedPositions = getCheckedItemPositions();
if (checkedPositions != null) {
checkedPositions = clone(checkedPositions);
}
super.clearChoices();
if (onItemCheckedListener != null && checkedPositions != null) {
for (int i = checkedPositions.size() - 1; i >= 0; i--) {
if (checkedPositions.valueAt(i)) {
onItemCheckedListener.onItemChecked(this, checkedPositions.keyAt(i), false);
}
}
}
}
@Override
publicvoid setItemChecked(int position, boolean value) {
super.setItemChecked(position, value);
if (onItemCheckedListener != null) {
onItemCheckedListener.onItemChecked(this, position, value);
}
}
publicvoid setOnItemCheckedListener(OnItemCheckedListener onItemCheckedListener) {
this.onItemCheckedListener = onItemCheckedListener;
}
}