Comments (5)
I don't have a sample of that in DataDroid but I have multiple apps doing that with DataDroid.
When we talk of endless ListView, it's more a paginated listview in fact. so every time you arrive at the end of the list, you load the next page and add it at the end of the list.
You just need to call the same webservice you called for the first page and have a parameter in the webservice specifying the page. Every time you successfully load a page, you increment the page number to retrieve and you are good to go.
You can detect that you are at the end of the current page using a OnScrollListener.
On thing to note : if you have an infinite number of pages, you need to remove some elements from your ArrayList at some points (limit the number of pages you have at the same time), otherwise you are going to end up with an OutOfMemoryException.
It's a ultra rare case (have a big enough number of pages to have this issue is ... uncommon), but it's good to think about it :)
If that's not enough I could add a sample for that but not right now (too many projects I have to finish first ^^)
from datadroid.
Thanks for the reply. I have tried to look at your sample code Person List sample. You are not using Array List to store and populate your ListView. Am I wrong? from what I understand in your code from JSON (server) to phone SQLlite (database) then to the ListView (UI). So where is the timing for the array list? Sorry I am new in android :) so please bear with me.
from datadroid.
If you want an example with an ArrayAdapter (backed by an ArrayList) you can check the City List sample
If you are using a SQLite database it's even easier for you. Keep the page system and add the new elements to your database. They will be automatically added to your listview by the CustorAdapter ! (and you don't have to bother with the out of memory issue in this case as the database is managing it for you)
Only thing you need to figure out is a way to request your elements sorted from the database so that they appear in the same order as the one returned by your webservice :)
from datadroid.
ok I get it it now :) I tried to look at the code in PersonListJsonFactory I notice this is the part we save from json to database. How can I check using there primary key if the person exist I will not add the record? can you give me some tips? I attached your sample code of PersonListJsonFactory
public static ArrayList<Person> parseResult(String wsResponse) throws DataException {
ArrayList<Person> personList = new ArrayList<Person>();
try {
JSONObject parser = new JSONObject(wsResponse);
JSONArray jsonPersonArray = parser.getJSONArray("results");
Log.d("result",wsResponse);
int size = jsonPersonArray.length();
for (int i = 0; i < size; i++) {
JSONObject jsonPerson = jsonPersonArray.getJSONObject(i);
Person person = new Person();
person.firstName = jsonPerson.getString(JSONTag.PERSON_LIST_ELEM_PERSON_FIRST_NAME);
person.lastName = jsonPerson.getString(JSONTag.PERSON_LIST_ELEM_PERSON_LAST_NAME);
person.email = jsonPerson.getString(JSONTag.PERSON_LIST_ELEM_PERSON_EMAIL);
person.city = jsonPerson.getString(JSONTag.PERSON_LIST_ELEM_PERSON_CITY);
person.postalCode = jsonPerson.getInt(JSONTag.PERSON_LIST_ELEM_PERSON_POSTAL_CODE);
person.age = jsonPerson.getInt(JSONTag.PERSON_LIST_ELEM_PERSON_AGE);
person.isWorking = jsonPerson.getInt(JSONTag.PERSON_LIST_ELEM_PERSON_IS_WORKING) == 1;
personList.add(person);
}
} catch (JSONException e) {
Log.e(TAG, "JSONException", e);
throw new DataException(e);
}
return personList;
}
from datadroid.
foxykeep,
I made it work :) thanks for the info! more power!
from datadroid.
Related Issues (20)
- BadParcelableException when reading a Parcelable from a Request inside an Operation HOT 2
- Trying to use datadroid and sliding menu HOT 3
- Count number of Records in a model HOT 3
- Array of values to parameters
- Httpurlconnection request with PUT method with cookies gives session invalid error. HOT 12
- UI isn't compatible with small screen
- Phone (CRUD) Sync issue
- Delivering result of network call to another activity. HOT 2
- how to apply migration to existing application HOT 1
- EOFException on some requests HOT 4
- SSL method in Android 2.2 HOT 2
- Sending Json Object as parameter in post method HOT 1
- Why have you decided to skip the approach of ContentProvider ? HOT 1
- Datadroid with Volley required! HOT 1
- Root for galaxy 5 HOT 1
- Send file use DataDroid
- Bug: no recycling of HttpClient HOT 3
- PoC Bug: Does not override applyBatch HOT 1
- PoC Feature: Demonstrate permissions HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from datadroid.