Simple Example of android waterfall stream

Source: Internet
Author: User

Main. xml
 
<? Xml version = "1.0" encoding = "UTF-8"?>
<ScrollView xmlns: android = "http://schemas.android.com/apk/res/android"
Android: id = "@ + id/arc_hf_search_result"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent">

<LinearLayout
Android: id = "@ + id/arc_hf_search_item"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: orientation = "vertical">
</LinearLayout>

</ScrollView>
 
ArcHFSearchResult. java
 
Public class ArcHFSearchResult extends Activity {
Protected static final String TAG = "ArcHFSearchResult ";
Private ScrollView svResult;
Private LinearLayout llItem;
Private String [] arrayStr;
Private int pageCount = 0;
Private int resultCount = 10000;
Private int eachCount = 3000;
Private View view;

/** Called when the activity is first created .*/
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
SvResult = (ScrollView) findViewById (R. id. arc_hf_search_result );
LlItem = (LinearLayout) findViewById (R. id. arc_hf_search_item );
SvResult. setOnTouchListener (svListener );
View = svResult. getChildAt (0 );
// The first 10000 data records to be displayed
ArrayStr = new String [resultCount];
For (int I = 0; I <resultCount; I ++ ){
ArrayStr [I] = I + "";
}
// Add data for the first time, and add 3000 data entries each time.
AddResult ();
}

Class svTouchListener implements OnTouchListener {
@ Override
Public boolean onTouch (View v, MotionEvent event ){
Switch (event. getAction ()){
Case MotionEvent. ACTION_DOWN:
Break;
Case MotionEvent. ACTION_UP:
// If a listener event is triggered with content and ScrollView is pulled to the bottom, load the data once.
If (svListener! = Null
& View! = Null
& View. getMeasuredHeight ()-20 <= svResult
. GetScrollY () + svResult. getHeight ()){
AddResult ();
}
Break;
Default:
Break;
}
Return false;
}
}

SvTouchListener svListener = new svTouchListener ();

/**
* Add result
*/
Protected void AddResult (){
If (eachCount * pageCount <resultCount ){
For (int I = 0; I <eachCount; I ++ ){
Int k = I + eachCount * pageCount;
If (k> = resultCount)
Break;
TextView TV = new TextView (this );
TV. setText ("hello world" + arrayStr [k]);
LlItem. addView (TV );
}
PageCount ++;
}
}
}

 


From oldfeel

Related Article

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.