Figure 4.19 contains class MainActivity
’s static
and instance variables. The String
constant SEARCHES
(line 31) represents the name of the file that will store the searches on the device. Lines 33–34 declare EditText
s that we’ll use to access the queries and tags that the user enters. Line 35 declares the SharedPreferences
instance variable savedSearches
, which will be used to manipulate the key–value pairs representing the user’s saved searches. Line 36 declares the ArrayList<String>
that will store the sorted tag names for the user’s searches. Line 37 declares the ArrayAdapter<String>
that uses the contents of the ArrayList<String>
as the source of the items displayed in MainActivity
’s ListView
.
30 // name of SharedPreferences XML file that stores the saved searches
31 private static final String SEARCHES = "searches";
32
33 private EditText queryEditText; // EditText where user enters a query
34 private EditText tagEditText; // EditText where user tags a query
35 private SharedPreferences savedSearches; // user's favorite searches
36 private ArrayList<String> tags; // list of tags for saved searches
37 private ArrayAdapter<String> adapter; // binds tags to ListView
38