简体   繁体   中英

Prepend item in ListView and show in top

i am facing a problem like , i am developing an android application where all the records coming from database using REST call and displayed using ListView. now on the same screen one button is there to post the new record.

when user click in the button to post the new recored it will come as popup(DialogFragment). if user post any record from there, the record should prepend to the ListView without any rest call.

the user should feel that recored add to the db and immediately displayed on the screen.

Thanks in advance and any help is appreciated.

So, I guess you are using a list adapter which extends from BaseAdapter or ArrayAdapter. After the user added a new record, you should add this into the list of records and than call the method notifyDataSetChanged() of the adapter. This way, the new record will be immediately displayed on the screen and you can later on add it into your database (before the activity be destroyed). Here you can see a example with notifyDataSetChanged()

How to correctly implement BaseAdapter.notifyDataSetChanged() in Android

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM