4.5.1. package and import Statements

Figure 4.17 shows the app’s package and import statements. The package statement (inserted in line 4 by the IDE when you created the project) indicates that the class in this file is part of the com.deitel.twittersearches package. Lines 6–26 import the classes and interfaces the app uses.

Lines 6–7 import the ArrayList and Collections classes from the java.util package. We use class ArrayList to maintain the list of tags for the saved searches, and class Collections to sort the tags so they appear in alphabetical order. Of the remaining import statements, we consider only those for the features introduced in this chapter:

• Class AlertDialog of package android.app (line 9) is used to display dialogs.

• Class ListActivity of package android.app (line 10) is MainActivity’s superclass, which provides the app’s ListView and methods for manipulating it.

• Class Context of package android.content (line 11) provides access to information about the environment in which the app is running and allows you to use various Android services. We’ll be using a constant from this class when we programmatically hide the soft keyboard after the user saves a search.

• Class DialogInterface of package android.content (line 12) contains the nested interface OnClickListener. We implement this interface to handle the events that occur when the user touches a button on an AlertDialog.

• Class Intent of package android.content (line 13) is used to create an object that specifies an action to be performed and the data to be acted upon—Android uses Intents to launch the appropriate activities. We’ll use this class to launch the device’s web browser to display Twitter search results and to display an intent chooser so the user can choose how to share a search.

• Class SharedPreferences of package android.content (line 14) is used to manipulate persistent key–value pairs that are stored in files associated with the app.

• Class Uri of package android.net (line 15) enables us to convert a URL into the format required by an Intent that launches the device’s web browser.

• Class View of package android.view (line 17) is used in various event-handling methods to represent the GUI component that the user interacted with to initiate an event.

• Class View contains the nested interface OnClickListener (line 18). We implement this interface to handle the event raised when the user touches the ImageButton for saving a search.

• Class InputMethodManager of package android.view.inputmethod (line 19) enables us to hide the soft keyboard when the user saves a search.

• Package android.widget (lines 20–26) contains the GUI components and layouts that are used in Android GUIs. Class AdapterView (line 20) is the base class of ListView and is used when setting up the ListView’s adapter (which supplies the ListView’s items). You implement interface AdapterView.OnItemClickListener (line 21) to respond when the user touches an item in a ListView. You implement interface AdapterView.OnItemLongClickListener (line 22) to respond when the user long presses an item in a ListView. Class ArrayAdapter (line 23) is used to bind items to a ListView. Class ImageButton (line 25) represents a button that displays an image.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.180.133