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