0

I can display the information of my phone application but I am restricted to display only six. I would like to know how to proceed to display the rest of the elements ( i have a list of 17 elements). For the moment I use the first and last columns of my Template to do an invalidate() and display the previous or next items of my list

    public Template onGetTemplate() {

        ListTemplate.Builder templateBuilder = new ListTemplate.Builder();

        ItemList.Builder sectionABuilder = new ItemList.Builder();

        if(compteur < 4 ) {
            try {
                if (DataMgr.getInstance().getDataListAdress().size() > 0 && compteur < DataMgr.getInstance().getDataListAdress().get(0).length) {
                    for (int i = compteur; i < compteur + 5; i++) {
                        System.out.println("////Test + " + DataMgr.getInstance().getDataListAdress().get(0)[i]);
                        System.out.println("////TestLength + " + DataMgr.getInstance().getDataListAdress().get(0).length);

                        sectionABuilder.addItem(buildRow(DataMgr.getInstance().getDataListAdress().get(0)[i]));
                    }
                }
                sectionABuilder.addItem(buildRowClick("Suivant"));

                templateBuilder.addSectionedList(
                        SectionedItemList.create(sectionABuilder.build(), "Header"));
            } catch (Exception e) {
                CarToast.makeText(getCarContext(), "No more", CarToast.LENGTH_SHORT).show();
            }
        } else {
            sectionABuilder.addItem(buildRowClickPrecedent("Precedent"));
            try {
                if (DataMgr.getInstance().getDataListAdress().size() > 0 && compteur < DataMgr.getInstance().getDataListAdress().get(0).length) {
                    for (int i = compteur; i < compteur + 4; i++) {
                        System.out.println("////Test + " + DataMgr.getInstance().getDataListAdress().get(0)[i]);
                        System.out.println("////Test +" + DataMgr.getInstance().getDataListAdress().get(0).length);

                        sectionABuilder.addItem(buildRow(DataMgr.getInstance().getDataListAdress().get(0)[i]));
                    }
                }
                sectionABuilder.addItem(buildRowClick("Suivant"));

                templateBuilder.addSectionedList(
                        SectionedItemList.create(sectionABuilder.build(), "Header"));
            } catch (Exception e) {
                CarToast.makeText(getCarContext(), "No more", CarToast.LENGTH_SHORT).show();
            }
        }

        return templateBuilder
                .setHeaderAction(Action.PAN)
                .setTitle("ok")
                .build();
    }


@NonNull
    private Row buildRow(String data) {
        return new Row.Builder()
                .setTitle(data)
                .build();
    }

    @NonNull
    private Row buildRowClick(String data) {
        return new Row.Builder()
                .setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick() {
                        compteur += 4;
                        invalidate();
                    }
                })
                .setTitle(data)
                .build();
    }

1 Answers1

0

You can't use it like this. Use ConstraintManager.class.

Lists are limited by unit you have in a car. But there is special API to handle this.

Check ConstraintManager:

int listLimit = Math.min(MAX_LIST_ITEMS,
                       getCarContext().getCarService(ConstraintManager.class).getContentLimit(
                                    ConstraintManager.CONTENT_LIMIT_TYPE_LIST));

Docs: https://developer.android.com/reference/androidx/car/app/constraints/ConstraintManager

You can take this limit count and interate your list only based on this number.

adek
  • 3,045
  • 2
  • 27
  • 41