GithubHelp home page GithubHelp logo

Endless ListView about datadroid HOT 5 CLOSED

foxykeep avatar foxykeep commented on June 13, 2024
Endless ListView

from datadroid.

Comments (5)

foxykeep avatar foxykeep commented on June 13, 2024

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.

ccfiel avatar ccfiel commented on June 13, 2024

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.

foxykeep avatar foxykeep commented on June 13, 2024

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.

ccfiel avatar ccfiel commented on June 13, 2024

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.

ccfiel avatar ccfiel commented on June 13, 2024

foxykeep,

I made it work :) thanks for the info! more power!

from datadroid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.