Android ApiDemos示例解析(176):Views->Lists->9. Array (Overlay)
以在屏幕上显示当前显示列表项的首字母以便于用户在列表中搜索。
本例是通过在屏幕中央显示一个文本框来实现的,通过WindowManager 为ListActivity缺省的窗口动态添加这个TextView.和大都数Android服务一样,WindowManager也是通过getSystemService来获取服务对象:
[java]
mWindowManager = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
mWindowManager = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
为ListView 添加Scroll 事件处理:
[java]
getListView().setOnScrollListener(this);
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
int lastItem = firstVisibleItem + visibleItemCount - 1;
if (mReady) {
char firstLetter = mStrings[firstVisibleItem].charAt(0);
if (!mShowing && firstLetter != mPrevLetter) {
mShowing = true;
mDialogText.setVisibility(View.VISIBLE);
}
mDialogText.setText(((Character)firstLetter).toString());
mHandler.removeCallbacks(mRemoveWindow);
mHandler.postDelayed(mRemoveWindow, 3000);
mPrevLetter = firstLetter;
}
}
getListView().setOnScrollListener(this);
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
int lastItem = firstVisibleItem + visibleItemCount - 1;
if (mReady) {
char firstLetter = mStrings[firstVisibleItem].charAt(0);
if (!mShowing && firstLetter != mPrevLetter) {
mShowing = true;
mDialogText.setVisibility(View.VISIBLE);
}
mDialogText.setText(((Character)firstLetter).toString());
mHandler.removeCallbacks(mRemoveWindow);
mHandler.postDelayed(mRemoveWindow, 3000);
mPrevLetter = firstLetter;
}
}
通过mHandler 在UI线程中发送消息,Android 系统Handler用法简介。
补充:移动开发 , Android ,