Building Out Locatr
Building Out Locatr
Time to create your interface. First, add a string for your search button in res/values/strings.xml.
Listing 33.1 Adding search button text (res/values/strings.xml)
You will be using a fragment, as usual, so rename activity_locatr.xml to fragment_locatr.xml.
Change out the insides of its RelativeLayout to have an ImageView to display the image you find
(Figure 33.7). (There are padding attribute values that come from the template code as of this writing.
They are not important, so feel free to leave them or delete them.)
Figure 33.7 Locatr’s layout (res/layout/fragment_locatr.xml)
You also need a button to trigger the search. You can use your toolbar for that. Create res/menu/
fragment_locatr.xml and add a menu item to display a location icon. (Yes, this is the same filename
as res/layout/fragment_locatr.xml. This is no problem at all: Menu resources live in a different
namespace.)
Listing 33.2 Setting up Locatr’s menu (res/menu/fragment_locatr.xml)
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_locate"
android:icon="@android:drawable/ic_menu_compass"
android:title="@string/search"
android:enabled="false"
app:showAsAction="ifRoom"/>
The button is disabled in XML by default. Later on, you will enable it once you are connected to Play
Services.