Refreshing listview content in Android

Source: Internet
Author: User

Recently I encountered a problem when learning the listview control of Android. How to add an item to the listview and refresh it in time. I have checked many posts on the Internet, and many people are asking and answering questions, but in general I have not found a detailed solution. For the synchronization between listview and the database, experts suggest using the contentprovider object. But what if I don't use a database? Someone also replied with the yydatasetchanged () method. This is a correct solution, but it is still confusing for new users. Here I will post my usage:

Code Onclicklistener listener2 =   New Onclicklistener (){
@ Override
Public   Void Onclick (view v ){
// Todo auto-generated method stub
Map < String, Object > M =   New Hashmap < String, Object > ();
String tistring = TV. gettext (). tostring (); // Note: Why should I retrieve the edittext content here?
M. Put ( " Prod_na " , Tistring ); // Write M. Put ("prod_na", TV. gettext ());
M. Put ( " Prod_type " , Tistring ); // Because TV. gettext () returns an editable object, the real data is cached,
// That is to say, your subsequent edittext changes will affect the previously added item.
Coll. Add (m );

// Retrieves the adapter object, which is used to call the yydatasetchanged method.
Simpleadapter sadapter = (Simpleadapter) LV. getadapter ();
Sadapter. notifydatasetchanged ();
}
};

 

Here we will discuss the MVC pattern concept in Android, how to store data, control and display.

You can think that listview is a view. What is the mode? It is obviously a simpleadapter object, and what is control? It can only be yydatasetchanged. When the data changes, that is, the data processed by simpleadapter changes, we need to call yydatasetchanged to notify the view to make a change.

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.