Question

I'm building an app on Glass using the GDK that has a large dataset for users to explore. (There is a voice input component, but I want to have a section for manual selection too as voice doesn't work for every data point.)

I generate cards in the way recommended, pushing cards with some text to an ArrayList and using the example card adapter to display the card. However, it seems like the system has difficulty in generating many cards and scrolling lags a lot when swiping between cards.

Additionally, even a set of six cards with text and images seem to lag using the example adapter from the docs.

For other developers, what have you done to optimize datasets to prevent any potential lag?

Here's some code in generating cards. I'm using pagination to display a small number of cards. (Max - min <= 50). It takes some time to generate so the system doesn't give any indication of what is happening.

public ArrayList<Card> getRange(int min, int max) {
    ArrayList<Card> cardStack = new ArrayList<Card>();
    Card prev = new Card(getApplicationContext());
    prev.setText("Loading a lot of Pokemon... hang on");
    setContentView(prev.toView());
    try {
        JSONArray wholedex = new JSONObject(loadJSONFromAsset()).getJSONArray("Data");
     //Save time by only reading the items we want. There are ~760 items, so 40 more than regular dex number
        for(int i=min-1;i<max+50;i++) {
            if(i > wholedex.length())
                continue;
            try {

                pkmn = new Pokemon(wholedex.getJSONObject(i));
                if(pkmn.getPokedexnumber() == min)
                    browseMin = i;
                if(pkmn.getPokedexnumber() >= min && pkmn.getPokedexnumber() <= max) {
                    Card temp = new Card(getApplicationContext());
                    temp.setText(pkmn.getPokedexnumber()+"   "+pkmn.getName());
                        cardStack.add(temp);
                }
            } catch(Exception e) {
                Log.d("Pokedex", e.getMessage());
            }
        }
        return cardStack;
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return null;
 }

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top