Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save listview in android and fetch it back when required?

I have a listview having three fields , but I don't know how to save my listview in android and fetch it back when user open app and display it.

I want to show the data saved in listview and I have to save the new data which user enter into my listview.

like image 327
Sid.The.Biker Avatar asked Dec 14 '15 04:12

Sid.The.Biker


People also ask

How to get data from ListView by Clicking item on ListView?

Try this: my_listview. setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { } });

How fetch data from sqlite database and show in ListView?

xml. Create an another layout file (list_row. xml) in /res/layout folder to show the data in listview, for that right click on layout folder à add new Layout resource file à Give name as list_row.

How check ListView is empty or not in android?

just check if (cartlist. size()<0) then yours list is Empty.!


2 Answers

I would recommend having some sort of database on a server that would save that information and that you would need to pull that information from the database to display it in the app. However, android also has something called a sharedpref that allows you to save stuff in the app when the app is closed. The link is below. However this is not the best way a database would be, but it may work for your needs.

http://developer.android.com/reference/android/content/SharedPreferences.html

like image 66
James Russo Avatar answered Oct 02 '22 19:10

James Russo


As per your requirment, there is no direct way to store list view, but you can store the data in the list view and you can set it in to the ListView later, for that you have to use Sqlite Database, refer official documentation of sqlite here, also check out this example.

read this example too (ListView of Data from SQLiteDatabase )

like image 30
droidev Avatar answered Oct 02 '22 19:10

droidev