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;/** called when the activity is first created. * // @ override public void oncreate (bundle savedinstanc Estate) {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); // arraystr = new string [resultcount]; for (INT I = 0; I <resultcount; I ++) {arraystr [I] = I + "";} // The First Time Add 3000 data records 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 and content exists, and scrollview is pulled to the bottom, load the data 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 ++ ;}}}
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.