Week 4 - ScrollView, SharedPreferences, Intents, LayoutInflater, AlertDialog, AndroidManifest.xml Flashcards
How does one gain access to the shared preferences?
This is typically done by requesting the default shared preferences for this activity from the preferences manager. The activity and default shared preferences can be substituted with other things.
Example:
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
What are Shared Preferences used for?
Shared Preferences are used to store simple data in the form of key-value pairs that needs to persist between invocations of an app.
How does one add data to, read, and remove data from the shared preferences?
After requesting the appropriate shared preferences, data can be added and removed by calling the getXXXXX(), putXXXXX(), and remove() methods of the shared preferences object.
What does the layout inflater do?
It constructs a concrete GUI that will be presented to the user from an XML layout file.
How is the layout inflator used?
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.xmlLayoutID, null);
How is an alert dialog created and shown?
AlertDialog.Builder b = AlertDialog.Builder(this);
b. setTitle(“Foo”);
b. setMessage(“Bar.”);
AlertDialog a = b.create();
a.show();
How does one make custom code execute when alert dialog buttons are clicked?
By setting a DialogInterface.OnClickListener.
Example:
builder.setPositiveButton("Text", New DialogInterface.OnClickListener() { // Some action } }
What does a ScrollView do?
A ScrollView is a container for views that can be scrolled by the user, allowing them to be larger than the screen. It is a FrameLayout and therefore should only contain one child view.
What is the difference between a ScrollView and a ListView?
A ScrollView offers more flexibility, whereas a ListView is optimised for scrollable lists.
What is the purpose of the Android Manifest XML file?
It contains important information about the app, such as:
- The activities that the app contains.
- Information about the SDK the app uses, e.g. minimum and target SDK versions.
- Which types on intents the app can listen for.