Android ListView Dynamic Load List entry implementation code _android

Source: Internet
Author: User

Recently a dynamic Loading ListView class table items, sharing out everyone learn to learn, talk about this example of the implementation process, first of all to limit the load of the list item data for 10 data, when the drag ListView scroll to the last data when loading 10, and displays the load prompt below the listview.

Here is my Java source code:

private void Showcontent () {ListView = (ListView) Findviewbyid (R.id.journals_list_one); 
  LoadData (); 
 
  adapter = new Mylistadapter (this, data); 
  Footerview = View.inflate (testlayout.this, R.layout.journal_listitem_loading_bar, NULL); 
 
  Listview.addfooterview (Footerview, NULL, TRUE); 
  Listview.setadapter (adapter); 
 Listview.setonscrolllistener (listener); Private Abslistview.onscrolllistener listener = new Abslistview.onscrolllistener () {@Override public void ONSC 
    Rollstatechanged (abslistview view, int scrollstate) {if (view.getlastvisibleposition () = = View.getcount ()-1) { 
    LoadData (); 
   Adapter.notifydatasetchanged (); @Override public void Onscroll (Abslistview view, int firstvisibleitem, int visibleitemcount, int total 
 
 ItemCount) {}};  
    /** * Construct list data/private void LoadData () {if (Data.size () <=) {for (int i = 0; i < i++) { map<string, string> map = new HASHMAp<string, string> (); 
    Map.put ("title", GetString (R.string.title)); 
    Map.put ("desc", GetString (r.string.content)); 
   Data.add (map); 
  } else {Listview.removefooterview (Footerview);  } 
 }

Implementation of this function is mainly to add ListView Onscrolllistener listening, to determine whether the list items to the most one, if the last one to load data. The load effect when loading data is that the Listview.addfooterview () method implement this method must be useful before listview.setadapter (). When all the data loading is complete, call Listview.removefooterview to remove Footerview.

If you want to learn more about Android ListView Friends can click to view the topic, more exciting: Android ListView use Method

The above is the entire content of this article, I hope to learn about Android software programming help, but also hope that we support the cloud habitat community.

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.