PlaceListMapTemplate.Builder()....setOnContentRefreshListener{// Execute any desired logic...// Then call invalidate() so onGetTemplate() is called againinvalidate()}.build()
Java
newPlaceListMapTemplate.Builder()....setOnContentRefreshListener(()->{// Execute any desired logic...// Then call invalidate() so onGetTemplate() is called againinvalidate();}).build();
[null,null,["上次更新時間:2025-08-09 (世界標準時間)。"],[],[],null,["# Build a point of interest app\n\nThis guide details the different features of the Car App Library\nthat you can use to implement the functionality of your point of interest (POI)\napp.\n\nDeclare category support in your manifest\n-----------------------------------------\n\nYour app needs to declare the `androidx.car.app.category.POI`\n[car app category](/training/cars/apps#supported-app-categories) in the intent filter of its\n[`CarAppService`](/reference/androidx/car/app/CarAppService).\n| **Important:** As of Car App Library version 1.3, the `androidx.car.app.category.PARKING` and `androidx.car.app.category.CHARGING` [car app categories](/training/cars/apps#supported-app-categories) are deprecated. Use the `androidx.car.app.category.POI` category instead.\n\nThe following example shows how to declare the app category: \n\n \u003capplication\u003e\n ...\n \u003cservice\n ...\n android:name=\".MyCarAppService\"\n android:exported=\"true\"\u003e\n \u003cintent-filter\u003e\n \u003caction android:name=\"androidx.car.app.CarAppService\" /\u003e\n \u003ccategory android:name=\"androidx.car.app.category.POI\"/\u003e\n \u003c/intent-filter\u003e\n \u003c/service\u003e\n ...\n \u003capplication\u003e\n\nAccess the map templates\n------------------------\n\nPOI apps can access the [`PlaceListMapTemplate`](/reference/androidx/car/app/model/PlaceListMapTemplate)\nand [`MapWithContentTemplate`](/reference/androidx/car/app/navigation/model/MapWithContentTemplate).\n\nThe `PlaceListMapTemplate` is specifically designed for showing a list of the\nPOIs alongside a map that is rendered by the host.\n\nThe `MapWithContentTemplate` can be used to display lists and other types of\ncontent alongside a map that is rendered by your app. See\n[Draw maps](/training/cars/apps#draw-maps) for more details on using this\ntemplate.\n\nTo access these templates, your app needs to declare the\n`androidx.car.app.MAP_TEMPLATES` permission in its `AndroidManifest.xml` file: \n\n \u003cmanifest ...\u003e\n ...\n \u003cuses-permission android:name=\"androidx.car.app.MAP_TEMPLATES\"/\u003e\n ...\n \u003c/manifest\u003e\n\n| **Note:** The `PlaceListMapTemplate` is available for use only by apps declaring the `androidx.car.app.category.POI` category or the deprecated `androidx.car.app.category.PARKING` or `androidx.car.app.category.CHARGING` categories. For navigation apps, see [Access the navigation templates](/training/cars/apps/navigation#access-navigation-templates).\n\nRefresh PlaceListMapTemplate content\n------------------------------------\n\nYou can let drivers refresh content with the tap of a button while browsing\nlists of places built with\n[`PlaceListMapTemplate`](/reference/androidx/car/app/model/PlaceListMapTemplate).\nImplement the\n[`OnContentRefreshListener`](/reference/androidx/car/app/model/OnContentRefreshListener)\ninterface's [`onContentRefreshRequested`](/reference/androidx/car/app/model/OnContentRefreshListener#onContentRefreshRequested())\nmethod, and use\n[`PlaceListMapTemplate.Builder.setOnContentRefreshListener`](/reference/kotlin/androidx/car/app/model/PlaceListMapTemplate.Builder#setoncontentrefreshlistener)\nto set the listener on the template to enable list refresh.\n\nThe following snippet shows how to set the listener on the template: \n\n### Kotlin\n\n```kotlin\nPlaceListMapTemplate.Builder()\n ...\n .setOnContentRefreshListener {\n // Execute any desired logic\n ...\n // Then call invalidate() so onGetTemplate() is called again\n invalidate()\n }\n .build()\n```\n\n### Java\n\n```java\nnew PlaceListMapTemplate.Builder()\n ...\n .setOnContentRefreshListener(() -\u003e {\n // Execute any desired logic\n ...\n // Then call invalidate() so onGetTemplate() is called again\n invalidate();\n })\n .build();\n```\n\nThe refresh button is only shown in the header of the\n`PlaceListMapTemplate` if the listener has a value.\n\nWhen the user clicks the refresh button, the `onContentRefreshRequested`\nmethod of your `OnContentRefreshListener` implementation is called. Within\n`onContentRefreshRequested`, call the\n[`Screen.invalidate`](/reference/androidx/car/app/Screen#invalidate())\nmethod. The host then calls back into your app's\n[`Screen.onGetTemplate`](/reference/androidx/car/app/Screen#onGetTemplate())\nmethod to retrieve the template with the refreshed content. See [Refresh the\ncontents of a template](/training/cars/apps#refresh-template) for more information about\nrefreshing templates. As long as the next template returned by `onGetTemplate`\nis of the same type, it is counted as a refresh and does not count toward the\ntemplate quota.\n\nIntegrate with Google Assistant using App Actions\n-------------------------------------------------\n\nVoice-enable your POI app using Assistant to allow users to search for points of\ninterest by asking things like, *\"Hey Google, find nearby charging stations on\nExampleApp\"* . For detailed instructions, see [App Actions for Cars](/guide/app-actions/cars).\n\n*** ** * ** ***"]]