You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
ListView: implement setSelection() and scrollTo()
This commit is contained in:
@@ -25,6 +25,7 @@ public abstract class AbsListView extends AdapterView {
|
||||
@Override
|
||||
protected native long native_constructor(Context context, AttributeSet attrs);
|
||||
protected native void native_setAdapter(long widget, ListAdapter adapter);
|
||||
protected native void native_scrollTo(long widget, int position);
|
||||
|
||||
public void setChoiceMode(int choiceMode) {}
|
||||
|
||||
@@ -73,6 +74,30 @@ public abstract class AbsListView extends AdapterView {
|
||||
|
||||
public void smoothScrollBy(int position, int duration) {}
|
||||
|
||||
public void smoothScrollToPositionFromTop(int position, int offset) {
|
||||
native_scrollTo(this.widget, position);
|
||||
}
|
||||
|
||||
private int pendingSelection = -1;
|
||||
@Override
|
||||
public void setSelection(int position, boolean animate) {
|
||||
super.setSelection(position, animate);
|
||||
native_scrollTo(this.widget, position);
|
||||
if (getWidth() > 0 && getHeight() > 0)
|
||||
native_scrollTo(AbsListView.this.widget, position);
|
||||
else
|
||||
pendingSelection = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void layout(int l, int t, int r, int b) {
|
||||
super.layout(l, t, r, b);
|
||||
if (pendingSelection != -1) {
|
||||
native_scrollTo(AbsListView.this.widget, pendingSelection);
|
||||
pendingSelection = -1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
|
||||
return new LayoutParams(getContext(), attrs);
|
||||
|
||||
@@ -36,6 +36,7 @@ public abstract class AdapterView extends ViewGroup {
|
||||
}
|
||||
|
||||
public void setSelection(int i) {
|
||||
setSelection(i, false);
|
||||
}
|
||||
|
||||
public void setOnItemSelectedListener(AdapterView.OnItemSelectedListener listener) {}
|
||||
|
||||
@@ -99,4 +99,9 @@ public class ListView extends AbsListView {
|
||||
}
|
||||
|
||||
public void setDividerHeight(int height) {}
|
||||
|
||||
@Override
|
||||
public void setSelection(int position, boolean animate) {
|
||||
super.setSelection(position + getHeaderViewsCount(), animate);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user