Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
278 views
in Technique[技术] by (71.8m points)

java - How to add more than 6 items in ItemList.Builder (Android- Auto)?

I am trying to develop apps compatible to car https://developer.android.com/training/cars . I forked official GitHub samples and successfully run the app https://github.com/android/car-samples/blob/main/Auto/car_app_library/showcase/src/main/java/com/google/android/libraries/car/app/samples/showcase/templates/ListTemplateDemoScreen.java. But the problem is 6 items can be displayed in a ListItemTemplate without any problem but I need to display more than 15 items. So if I add more than 6 rows I am getting exception.

I have tried:

ItemList.Builder listBuilder = ItemList.builder();

    listBuilder.addItem(
        Row.builder()
            .setOnClickListener(ParkedOnlyOnClickListener.create(() -> onClick("Parked action")))
            .setTitle("Parked Only Title")
            .addText("More Parked only text.")
            .build());

    for (int i = 2; i <= 15; ++i) { //if items < 6 then it works fine
      final String onClickText = "Clicked row: " + i;
      listBuilder.addItem(
          Row.builder()
              .setOnClickListener(() -> onClick(onClickText))
              .setTitle("Title " + i)
              .addText("First line of text")
              .addText("Second line of text")
              .build());
    }

Exception - Caused by: java.lang.IllegalArgumentException: The number of added rows exceeded the supported max of 6

I am using 'com.google.android.libraries.car:car-app:1.0.0-beta.1' library for development.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

ListTemplate : A template representing a list of items.

This template allows up to 6 Rows total in the ItemList(s). The host will ignore any items over that limit. Each Rows can add up to 2 lines of texts via Row.Builder.addText(CharSequence).

As a result, you cannot perform this action.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...