Android ApiDemos example resolution (176): Views-& gt; Lists-& gt; 9. Arr

Source: Internet
Author: User

To display the first letter of the currently displayed list item on the screen for users to search in the list.

In this example, a text box is displayed in the center of the screen. The TextView is dynamically added to the default window of ListActivity in WindowManager. like Android services, WindowManager also obtains service objects through getSystemService:


[Java]
MWindowManager = (WindowManager) getSystemService (Context. WINDOW_SERVICE );

MWindowManager = (WindowManager) getSystemService (Context. WINDOW_SERVICE );

Add Scroll event processing for ListView:

 

[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 is used to send messages in the UI thread. The usage of Android Handler is described.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.