0

I have a simple PaneTemplate I am setting up like this:

Row row1 = new Row.Builder().setTitle("Do Thing 1").build();
Row row2 = new Row.Builder().setTitle("Do Thing 2").build();
Row row3 = new Row.Builder().setTitle("Do Thing 3").build();
Row row4 = new Row.Builder().setTitle("Do Thing 4").build();
return new PaneTemplate.Builder(new Pane.Builder().addRow(row1).addRow(row2).addRow(row3).addRow(row4).build()).setTitle("AA Hello!!").build();

and it all works fine and looks like this:

enter image description here

but if I add setOnClickListener to one of the rows:

Row row1 = new Row.Builder().setTitle("Do Thing 1").setOnClickListener(this::onClick).build();

I get an exception: "a click listener is not allowed on the row"

enter image description here

I get an error:

I have not read about this restriction in any of the AA documentation. I tried making the onClick function anything number of things, including a blank function, and it makes no difference. Any idea what is going on here? How can I get around it? I want the press of this item to do something.

Uberbug
  • 97
  • 9

1 Answers1

1

It's restricted on PaneTemplate.

Using ListTemplate for such simple list is better decision.

  • I preliminarily tried that and it worked! I can add an onClickListener to a row in a ListTemplate and it works. If someone could point me to the docs where it says what is and is not allowed on the different templates I'd appreciate it. – Uberbug Jan 27 '22 at 17:11
  • read the requirements https://developer.android.com/reference/androidx/car/app/model/PaneTemplate.Builder#requirements – Vladyslav Berdnikov Jan 28 '22 at 11:53