整合了Android ListView分组界面布局改进和java实现List中汉字字母混排序,实现了类似iOS那样的快速定位效果,如下图: ? ? 主要是MainActivity实现了 OnTouchListener和OnGestureListener接口。 其中onScroll方法如下: @Override ??? util(e2); ??? return false; util方法,根据手势位置,确定快速定位到那个字母: public void util(MotionEvent e2) { ??? case 1: ??? case 2: ??? case 3: ??? case 4: ??? case 5: ??????? break; ??? case 6: ??????? break; ??? case 7: ??????? break; ??? case 8: ??????? break; ??? case 9: ??????? break; ??? case 10: ??????? break; ??? case 11: ??????? break; ??? case 12: ??????? break; ??? case 13: ??????? break; ??? case 14: ??????? break; ??? case 15: ??????? break; ??? case 16: ??? case 17: ??????? break; ??? case 18: ??????? break; ??? case 19: ??? case 20: ??????? break; ??? case 21: ??????? break; ??? case 22: ??????? break; ??? case 23: ??????? break; ??? case 24: ??????? break; ??? case 25: ??????? break; ??? default: 这样就实现了随手势在右边区域滑动,listview快速定位。 快速滑动首字母提示参见:ListView快速滑动示例增加首字母提示。 源代码见:http://bigcateasymorse.googlecode.com/svn/trunk/android-listview-separate-demo0.5/ ? ?
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
??????? float distanceY) {
}
??? int i = (int) ((e2.getRawY() – view.getTop()) / ((float) view
??????????? .getHeight() / 26f));
??? int j=0;
??? switch (i) {
??? case 0:
??????? int pos = (myAdapter).getPositionForSection(j++);
??????? listView.setSelectionFromTop(pos, 0);
??????? break;
??????? pos = (myAdapter).getPositionForSection(j++);
??????? listView.setSelectionFromTop(pos, 0);
??????? break;
??????? pos = (myAdapter).getPositionForSection(j++);
??????? listView.setSelectionFromTop(pos, 0);
??????? break;
??????? pos = (myAdapter).getPositionForSection(j++);
??????? listView.setSelectionFromTop(pos, 0);
??????? break;
??????? pos = (myAdapter).getPositionForSection(j++);
??????? listView.setSelectionFromTop(pos, 0);
??????? break;
??????? pos = (myAdapter).getPositionForSection(j++);
??????? listView.setSelectionFromTop(pos, 0);
??????? pos = (myAdapter).getPositionForSection(j++);
??????? listView.setSelectionFromTop(pos, 0);
??????? pos = (myAdapter).getPositionForSection(j++);
??????? listView.setSelectionFromTop(pos, 0);
??????? pos = (myAdapter).getPositionForSection(j++);
??????? listView.setSelectionFromTop(pos, 0);
??????? pos = (myAdapter).getPositionForSection(j++);
??????? listView.setSelectionFromTop(pos, 0);
??????? pos = (myAdapter).getPositionForSection(j++);
??????? listView.setSelectionFromTop(pos, 0);
??????? pos = (myAdapter).getPositionForSection(j++);
??????? listView.setSelectionFromTop(pos, 0);
??????? pos = (myAdapter).getPositionForSection(j++);
??????? listView.setSelectionFromTop(pos, 0);
??????? pos = (myAdapter).getPositionForSection(j++);
??????? listView.setSelectionFromTop(pos, 0);
??????? pos = (myAdapter).getPositionForSection(j++);
??????? listView.setSelectionFromTop(pos, 0);
??????? pos = (myAdapter).getPositionForSection(j++);
??????? listView.setSelectionFromTop(pos, 0);
??????? pos = (myAdapter).getPositionForSection(j++);
??????? listView.setSelectionFromTop(pos, 0);
??????? pos = (myAdapter).getPositionForSection(j++);
??????? listView.setSelectionFromTop(pos, 0);
??????? pos = (myAdapter).getPositionForSection(j++);
??????? listView.setSelectionFromTop(pos, 0);
??????? pos = (myAdapter).getPositionForSection(j++);
??????? listView.setSelectionFromTop(pos, 0);
??????? pos = (myAdapter).getPositionForSection(j++);
??????? listView.setSelectionFromTop(pos, 0);
??????? pos = (myAdapter).getPositionForSection(j++);
??????? listView.setSelectionFromTop(pos, 0);
??????? pos = (myAdapter).getPositionForSection(j++);
??????? listView.setSelectionFromTop(pos, 0);
??????? pos = (myAdapter).getPositionForSection(j++);
??????? listView.setSelectionFromTop(pos, 0);
??????? pos = (myAdapter).getPositionForSection(j++);
??????? listView.setSelectionFromTop(pos, 0);
??????? pos = (myAdapter).getPositionForSection(j++);
??????? listView.setSelectionFromTop(pos, 0);
??????? break;
??? }
}
?
?
?