From 636e6bd21f25528a00f0629e18504eadc315bda7 Mon Sep 17 00:00:00 2001 From: Beginning Android Date: Wed, 27 Jul 2016 10:31:25 -0700 Subject: [PATCH] 1.18 Add empty view to the ListView --- .../example/android/pets/CatalogActivity.java | 7 ++++ app/src/main/res/layout/activity_catalog.xml | 38 +++++++++++++++++++ app/src/main/res/values/strings.xml | 6 +++ 3 files changed, 51 insertions(+) diff --git a/app/src/main/java/com/example/android/pets/CatalogActivity.java b/app/src/main/java/com/example/android/pets/CatalogActivity.java index 728e4b34..7992ffbe 100755 --- a/app/src/main/java/com/example/android/pets/CatalogActivity.java +++ b/app/src/main/java/com/example/android/pets/CatalogActivity.java @@ -48,6 +48,13 @@ public void onClick(View view) { startActivity(intent); } }); + + // Find the ListView which will be populated with the pet data + ListView petListView = (ListView) findViewById(R.id.list); + + // Find and set empty view on the ListView, so that it only shows when the list has 0 items. + View emptyView = findViewById(R.id.empty_view); + petListView.setEmptyView(emptyView); } @Override diff --git a/app/src/main/res/layout/activity_catalog.xml b/app/src/main/res/layout/activity_catalog.xml index 5e7c77a0..94b0a93d 100755 --- a/app/src/main/res/layout/activity_catalog.xml +++ b/app/src/main/res/layout/activity_catalog.xml @@ -23,6 +23,44 @@ android:layout_width="match_parent" android:layout_height="match_parent"/> + + + + + + + + + + Delete All Pets + + It\'s a bit lonely here... + + + Get started by adding a pet + Add a Pet