03A Fragments and MVC Flashcards

1
Q

Fragments

A

• A fragment is an independent module with its own user interface
• You can create a fragment without a UI to
handle background tasks, but this is not the usual case
• Fragments exist only when embedded within an Activity

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Creating Fragments

A

• Within Android Studio you can right-click on the “app” root, select New, and select
Fragment
• You’ll be presented with three choices:
– Fragment (blank)
– Fragment (list)
– Fragment (with a +1 button)
• Your fragment will have a layout defined in the XML
• The code for your fragment will be an inner class within the main class
• Your fragment extends the Fragment class
• If you have a UI, override the
onCreateView method to inflate it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

The Fragment Lifecycle

A

Fragment.onAttach->Fragment.onCreate-> Fragment.onCreateView-> Fragment.onActivityCreated (Visible) Fragment.onStart-> (Active)
Fragment.onResume->Fragment->onPause-> Fragment->onPause-> Fragment.onDestroyView-> Fragment-> onDestroy->Fragment->onDetach

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Fragments and Activities

A

• You can get a reference to the activity in
which the fragment exists:
MainActivity main = (MainActivity)getActivity();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Compound Controls

A
  • Compound controls are self-contained View Groups that contain multiple child views
  • These can be treated as a single control
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Model-View-Controller (intro)

A
  • This paradigm is used for many controls, but in particular, you’ll need it for lists
  • The Model is the actual data
  • The View is how the data are displayed
  • The Controller gets input
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

MVC (JList)

A
  • JList does not have an “add” method
  • Therefore, to add something to the list on the screen, you must add it to the model
  • The View implements ActionListener to get events from the model when the data changes
  • Views can show the data in different ways, depending upon the renderer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

JSpinner Models

A
  • The JSpinner control has several models:
  • SpinnerDateModel to cycle through dates • SpinnerNumberModel for numbers (default)
  • SpinnerListModel cycles through the items in a list
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

The JList Control Revisited

A

• The appearance of JList is controlled by the
Cell Renderer
• These implement the ListCellRenderer
interface, which defines the
getListCellRendererComponent method
• Thus the appropriate Cell Renderer can
display anything in a list
• ListCellRenderer subclasses should handle the cases where the cell is selected and where it is not, and whether it has the focus
• These attributes are passed as parameters to the getListCellRenderer method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly