FIT2081 Lecture Notes - Lecture 6: Hash Table, Xml, Mdpi

153 views8 pages
CardView
!"#$%&'(FrameLayout )*+'',(*$#'(-./('0.1(2%3.45+#2.%(2%'2&$()+4&'(
#0+#(0+6$(+().%'2'#$%#(*..7(+)4.''(#0$(8*+#3.45
9
:2&;$#'()+%(0+6$('0+&.1'(+%&(4./%&$&().4%$4'9
<+%(+*'.(=$(/'$&(+'(#$58*+#$(3.4($+)0(2#$5(2%(+(ListItem .4(
RecyclerView
9
<+%(=$(&4+;;$&(+%&(&4.88$&(34.5(>+*$##$9
RecyclerView ?@($332)2$%#(ListViewsA
B().%#+2%$4(3.4(&2'8*+-2%;(*+4;$(&+#+('$#'(#0+#()+%(=$(')4.**$&(6$4-(
$332)2$%#*-(=-(5+2%#+2%2%;(+(*252#$&(%/5=$4(.3(4$)-)*$&(62$1'
9
C$'#(#.(/'$(12#0(&+#+().**$)#2.%'(10.'$($*$5$%#'()0+%;$(+#(4/%#25$
=+'$&(.%(/'$4(+)#2.%(.4(%$#1.47($6$%#'
9
<+%(=$(&4+;;$&(+%&(&4.88$&(34.5(>+*$##$
9
RecyclerView.LayoutManager layoutManager; 84.62&$'('252*+4(
3/%)#2.%+*2#-(#.(ListView
<+%(=$(+''2;%$&(2%($2#0$4(DEF(.4(G+6+
9
ViewHolder
9
:.47'(+'(+(=42&;$(=$#1$$%(#0$(DEF(+%&(G+6+
9
I$&/)$'(#0$(%/5=$4(.3 findViewById() )+**'( 1$(%$$&(#.(5+7$,(+'(
#0$-(+4$($"8$%'26$
9
I$)-)*$4($"#$%&'(
RecyclerView.Adapter<RecylerAdapter.ViewHolder>
J%(#02'()+'$,('8$)232)(&+#+(#-8$(2'(+%-(#-8$(#0+#($"#$%&'(ViewHolder
9
9
N+6$'(+&&4$''$'(.=#+2%$&(=-(findViewById 2%(+(0+'0(5+8,(#0$%(.%*-(
/'$'(2#(+;+2%(10$%(+&&4$''$'(%$$&$&(+4$%O#(2%(0+'0(5+8
9
P$'#$&(2%'2&$(+&+8#$4()*+'',('2%)$(#0+#(2'(#0$(.%*-(8*+)$(2#(12**(=$(
4$3$4$%)$&
9
RecyclerView.Adapter
B(+()*+''()+**$&( Adapter %$'#$&(2%'2&$(#0$(RecyclerView )*+''
H))$8#'(*2'#(.3(2#$5'(34.5(MainActivity )*+'',(=/2*&'(CardViews +%&(=2%&'(
&+#+(#.(#0$5
B(02;0*-Q'8$)2+*2'$&()*+''(#0+#()+%(.%*-('$46$(+'(+%(+&+8#$4(#.(RecyclerView
R..&().&$(.4;+%2'+#2.%(2%(H>J(#.(%$'#(2#(2%'2&$(RecyclerView )*+''
P$$&'S
onCreateViewHolder, onBindViewHolder, getItemCount
ViewHolder '/=)*+''(?extends RecyclerView.ViewHolderA(
#.(258*$5$%#(T(.6$442&$(2#'()#.4
9
U+#+(VQQQQQ@(+&+8#$4(?'/=)*+''(.3(RecyclerView.AdapterA(VQQQQQ@(
RecyclerView
W(+&+8#$4(5$#0.&'(?)+**$&(4$8$+#$&*-(=-(2%#$4%+*(H>J().&$(#.(=/2*&(
RecyclerView *2'#A
onCreateViewHolder(ViewGroup parent, int viewType) Q
)4$+#$'(+(ViewHolder 2%'#+%)$(3.4(+(*2'#(2#$5
J'(8+''$&(+(4$3$4$%)$(#.(#0$(ViewGroup #0+#(12**().%#+2%(#0$(*2'#(
2#$5
X0$(*2'#(2#$5O'(*+-./#(2'(2%3*+#$&(2%#.(#0$(ViewGroup
ViewHolder 2%'#+%)$()4$+#$&(?/'2%;(4$3$4$%)$(#.(CardView
2%'#+%)$(8+''$&(2%#.(2#'()#.4A
<#.4('#.4$'(+**(4$3'(#.(12&;$#'(2%(CardView 2%'#+%)$(#0+#(12**(
%$$&(&+#+Y*2'#$%$4(=2%&2%;
§
Z8+4'$'(2#'(6+*/$'(#.(onBindViewHolder
9
onBindViewHolder(VH holder, int position, List<Object>
payloads) Q=2%&'(+(*2'#(2#$5O'(&+#+(#.(2#'(ViewHolder 2%'#+%)$
>+''$&(#0$(%$1*-()4$+#$&(ViewHolder 2%'#+%)$(?8+4'$&(34.5(
onCreateViewHolderA(?3/**(.3(12&;$#(+&&4$''$'(3.4(+''.)2+#$&(
CardView 2%'#+%)$A(#;#(12#0(#0$(8.'2#2.%(2%(+&+8#$4O'(&+#+('$#(.3(
#0$(&+#+(#0$(L2$1[.*&$4(5/'#(=2%&(#.
:2&;$#'(2%(ViewHolder's +''.)2+#$&(CardView 2%'#+%)$(+4$(
=./%&(#.(&+#+
F2'#$%$4'()4$+#$&(+%&(+''2;%$&(+'(4$\/24$&(?/'/+**-(*2'#$%2%;(3.4(
onClickA
9
getItemCount() Q2%#$4%+*(H>J(/'$
P$$&(#.(.6$442&$(#.(#$**(H%&4.2&(10$#0$4(-./O4$().%'2&$42%;(#0$(
10.*$(+44+-(.4(+()$4#+2%(%/5=$4(.3(2#$5'(2%(#0$(+44+-(#.(=$(
&2'8*+-$&
9
Toolbar
?app:popupTheme:"@style/AppTheme.PopupOverlay"A()0+%;$'().*./4(
.3(.8#2.%(5$%/(8.8(/8(3.4(*$;2=2*2#-
N$#(#.(+)#(+'(H)#2.%(C+4(3.4(H)#262#-(12%&.1,(2%'#$+&(.3(/'2%;(ActionBar
?5.4$(&$#+2*'(2%(:$$7(]A
9
CoordinatorLayout
9
?android:fitsSystemWindows="true"A(5+7$'('/4$().58.%$%#(+**.1'(3.4(
'#+#/'(=+4
RecyclerView
?app:layout_behaviour="@string/appbar_scrolling_view_b
ehaviour"A(5/'#(0+6$,(23(%.#(RecyclerView ')4.**'(H88(C+4(324'#(
=$3.4$(')4.**2%;(RecyclerView
AppBarLayout
?android:theme="@style/AppTheme.AppBarOverlay"A(
2%6$4#'().*./42%;(#.(5+7$(#$"#(+%&(2).%'(2%(H88(C+4(5.4$(*$;2=*$( .%(
+%(25+;$(=+)7;4./%&^
L$4#2)+*(LinearLayout 102)0(258*$5$%#'(5+%-(.3(#0$(
3$+#/4$'(.3(EUO'(H88(C+4().%)$8#,(%+5$*-(')4.**2%;(;$'#/4$'
§
U$8$%&'(0$+62*-(.%(=$2%;(/'$&(+'(+(&24$)#()02*&(12#02%(+(
CoordinatorLayout
§
CollapsingToolbarLayout B(+(14+88$4(3.4(Toolbar
102)0(258*$5$%#'(+().**+8'2%;(+88(=+4
§
?2%2#2+*2'$&(2%'2&$(onCreateA
?android:layout_scrollFlags="scroll|enterAlwa
ys"A(')4.**(.3(')4$$%(&/42%;(/81+4&(')4.**(_(')4.**(.%(')4$$%(
&/42%;(&.1%1+4&(')4.**^(:2#0./#(#02'(H88(C+4(&.$'%O#(')4.**(
+#(+**,(RecyclerView 2%0$4$%#*-(')4.**'(.3)^
?android:fitsSystemWindows="true"A
U$'2;%$&(#.(=$(+(&24$)#()02*&(.3(AppBarLayout`
findViewById(R.id.collapsing_toolbar);
`
ImageView +%&(Toolbar %$'#$&`
<+4&U$5.aH88C+4bcdeN#/&$%#
F26$N#.)7H88N#/&$%#
E+'#$4U$#+2*bcdeN#/&$%#
Adapter
B(=2%&'(+88Q'8$)232)(&+#+(#.(62$1'(&2'8*+-$&(
?12#02%(+(RecyclerView 2%(#02'()+'$A
U+#+(%.45+**-('./4)$&(34.5(+(&+#+=+'$(62+(<>
What%does%this%code%do?
H(%$1(C/%&*$(2'('8$)232$&(+'(+%(+4;/5$%#^
H4;/5$%#'(2'(#.*&(#.(8/#(+('#42%;(#0+#(;4+='(#0$(f4+;5$%#(+4;/5$%#(4$84$'$%#2%;(#0$(
2#$5(JU(#0+#(#02'(f4+;5$%#(4$84$'$%#'^
H(%$1(f4+;5$%#(2'()4$+#$&(#.(=$(8*+)$&(2%(#0$(H)#262#-(*+-./#^
X0$(f4+;5$%#(2%8/#(2'(#0$('#42%;(34.5(=$3.4$^
getSupportFragmentManager() 2'()+**$&( #.(;$#(+(f4+;5$%#(E+%+;$4(/'2%;(#0$(
'/88.4#(*2=4+4-(H>J'^
beginTransaction() 2'()4$+#$&(#.()4$+#$(+(f4+;5$%#(#4+%'+)#2.%^
add() +&&'(f4+;5$%#(#.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%(7$-(+6+2*+=2*2#-(Q%+6$"8.'$&,(%+602&&$%9
>425+4-(%.%Q#./)0(%+62;(5$#0.&(Q%.%+6,(&8+&,(#4+)7=+**,(10$$*9
>*+#3.45(6$4'2.%(?H>J(*$6$*A(Q6W,(6],l9
I/*$'(.3(/'2%;().%32;/4+#2.%(\/+*232$4(%+5$'
<+%('8$)23-(5/*#28*$(\/+*232$4'(3.4(+('2%;*$('$#(.3(4$'./4)$',('$8+4+#$&(=-(
&+'0$'(?$;^(&4+1+=*$Q$%Q4KNQ*+%&A
9
E/'#(=$(2%(.4&$4(?&4+1+=*$Q8.4#Q0&82(PmX(0&82Q8.4#A9
<+%%.#(=$(%$'#$&9
L+*/$'(+4$()+'$('$%'2#26$9
m%*-(.%$(6+*/$(3.4($+)0(\/+*232$4(#-8$(2'('/88.4#$&(?&4+1+=*$Q4!NQ4fI(PmX(
8.''2=*$,(5/'#(0+6$(b(4$'./4)$(&24$)#.42$'A
9
Fragments
B(+('$*3Q).%#+2%$&,(5.&/*+4('$)#2.%(.3(+%(+88O'(KJ(+%&().44$'8.%&2%;(=$0+62./4(
#0+#()+%(=$($5=$&&$&(12#02%(+%(H)#262#-
B(4$84$'$%#(+(=$0+62./4Y8.4#2.%(.3(KJ(2%(+%(H)#262#-
[+6$(.1%(KJ(+%&(*+-./#9
F23$)-)*$(?ee()+**=+)7'A
onAttach()
onCreate()
getSupportFragmentManager .=#+2%'(34+;5$%#(5+%+;$4(
/'2%;('/88.4#(*2=4+4-(H>J'
§
B(+&&'(+(Fragment #.(84$62./'(*+-./#
beginTransaction()
N#+4#'(+(Fragment #4+%'+)#2.%(?&+#+(#4+%'+)#2.%A
®
`
replace?4$3$4$%)$(#.(?2&(.3A(View #0+#(12**().%#+2%(#0$(
34+;5$%#(gI^2&^aaah,(34+;5$%#(4$8*+)2%;(10+#$6$4(1+'(2%(
#0$(ViewA
I$8*+)$'(10+#$6$4(2'(2%(#0$('8$)232$&().%#+2%$4(
12#0(#02'(Fragment
®
K'$&(10$%(+(Fragment %$$&'(#.(=$()0+%;$&(+%&(
+&&$&(#.(#0$(=+)7'#+)7(&/42%;(#0$(H)#262#-O'(*23$
®
`
add(4$3$4$%)$(#.(?2&(.3A(View #0+#(12**().%#+2%(#0$(
34+;5$%#(gI^2&^aaah, Fragment =$2%;(+&&$&(#.(#0$(
View)
`
commit(); '+6$'(+**(&+#+,(4$+&-(#.(=$(*+/%)0$&(2%(
34+;5$%#(#.(+88*-()0+%;$'^
I$#/4%'(true 23('/))$''3/*(.4(false 23(3+2*$&
®
`
N)0$&/*$'(&+#+(#4+%'+)#2.%(#.(4/%(.%(+)#262#-O'(KJ(#04$+&(
?n5+2%n(#04$+&A(+'('..%(+'(#04$+&(2'(+=*$(#.(&.('.
`
J3(5/*#28*$()0+%;$'(5+&$(2%(+('2%;*$(#4+%'+)#2.%(+%&(
addToBackStack?34+;5$%#O'(#+;A(2'()+**$&,(+**()0+%;$'(
=$3.4$(commit() +4$(+&&$&(#.(=+)7('#+)7(+'(+('2%;*$(
#4+%'+)#2.%,(+%&(Back =/##.%(4$6$4'$'(#0$5(+**(#;#
`
onCreateView()
public class ItemDetailFragment extends
Fragment {
@Override
public View onCreateView
(LayoutInflater inflater, ViewGroup
container, Bundle savedInstanceState) {
return inflater.inflate
(R.layout.__, container, false);
}
}
onActivityCreated()
onStart()
onResume()
f4+;5$%#(2'(+)#26$
§
K'$4(%+62;+#$'(=+)71+4&'Yf4+;5$%#(2'(4$5.6$&(.4(4$8*+)$&`
mI(f4+;5$%#(+&&$&(#.(=+)7'#+)7,(#0$%(4$5.6$&(.4(4$8*+)$&`
onPause()
onStop()
onDestroyView()
onDestroy()
onDetach()
9
setArguments(Bundle arguments)
N+6$'(&+#+(#0+#(%$$&'(#.(=$(8+''$&(34.5(#0$(H)#262#-(#.(#0$(2%2#2+*2'2%;(
Fragment,('.(10$%(#0$(H)#262#-(4$*+/%)0$'(2%#.(#0$(Fragment,(#0$(
&+#+(12**(=$(#0$('+5$^
P.(%$$&(Bundle 23(%.(&+#+Y2%3.(345($"#$4%+*('./4)$(2'(4$\/24$&
H**.1'(Fragment +%&(2#'(H)#262#-(#.().55/%2)+#$(+%&(8+''(
&+#+(=$#1$$%($+)0(.#0$4
`
[under onCreate]
if(getArguments() != null) {
mParam1 =
getArguments().getString("key1");
}
9
g34.5(:$$7(oh9
findFragmentByTag(String tag)
X.(+))$''(%$1(34+;5$%#,(+&&(2#(#.(=+)7'#+)7(/'2%;(#0$(34+;5$%#O'(
/%2\/$(#+;(+'(+(4$3$4$%)$
X02'(12**(*..7(#04./;0(=+)7('#+)7(/%#2*(#0$(#+;(2'(3./%&
m%*-(8.''2=*$(84.=*$5(2'(5+2%#+2%2%;(#+;'(+%&(7$$82%;(#0$5(/%2\/$
9
X+;
E/'#(0+6$(=$$%(;26$%($2#0$4(10$%(2%3*+#$&(34.5(DEF
m4(+'('/88*2$&(10$%(+&&$&(2%(+(#4+%'+)#2.%
9
U233(=$#1$$%(H)#262#2$'(+%&(f4+;5$%#'S
f4+;5$%#'(5/'#(=$(%$'#$&(12#02%(+%(H)#262#-,()+%%.#(=$()4$+#$&(12#0./#(+%(
H)#262#-(#.('/88.4#(#0$5^
e^
[.1$6$4(H)#262#$'()+%%.#(=$(%$'#$&(12#02%(f4+;5$%#'^
E/*#28*$(34+;5$%#'()+%(4/%(.%(+('2%;*$(')4$$%(+#(#0$('+5$(#25$,(%.#(
8.''2=*$(3.4(H)#262#2$'^
b^
f4+;5$%#'()+%(=$(4$/'$&(#04./;0./#(5/*#28*$(H)#262#2$'^W^
f4+;5$%#'O(*23$)-)*$'(+4$(&$8$%&$%#(.%(#0$(H)#262#-(#0$-(+4$(%$'#$&(2%,(%.#(
).58*$#$*-(2%&$8$%&$%#(*27$(+%(H)#262#-O'^
]^
gF26$N#.)7H88N#/&$%#h
X.(4$#42$6$(&+#+(34.5(+(4$+*(1$=('$46$4(/'2%;([XX>(4$\/$'#'
H88('$%&'(4$\/$'#(#.(1$='2#$
0##8'SYY111^+*80+6+%#+;$^).Y\/$4-p
3/%)#2.%BXJE!aN!IJ!NaJPXIHUHMq'-5=.*BRmmRFq2%#$46+*B
er52%q+827$-B>KdR>LG<UMECCHsf
0##8'SYY111^+*80+6+%#+;$^). @@@(4$5.#$('$46$4
XJE!aN!IJ!NaJPXIHUHM(@@@(4$\24$&(3/%)#2.%
RmmRF(@@@( N#.)7(N-5=.*((?R..;*$A
er52%(@@@(2%#$46+*^(m#0$4(6+*/$'S(r,(ec,(Wc
>KdR>LG<UMECCHsf(@@@(H>J(7$-(?34$$(+%&(*23$#25$A
makeRequest(): +()+**=+)7(2%6.7$&(10$%(+(4$'8.%'$(.))/4'
<4$+#$'(6.**$-(8+)7+;$(2%(\/$/$
GNmP('#/33(;.$'(.%(#.($"#4+)#(&+#+(+%&(8/#(2%#.(+%(ArrayList
?dataItemsA
N$%&(&+#+(#.(4$)-)*$4(+&+8#$4 #.()4$+#$(62$1'(Q)4$+#$(%$1(.%$,(
setAdapter(new one)
H&&(4$\/$'#(#.(\/$/$
Week$6
X/$'&+-,( bi(E+-(bced
eeScc
Unlock document

This preview shows pages 1-3 of the document.
Unlock all 8 pages and 3 million more documents.

Already have an account? Log in
CardView
!"#$%&'(FrameLayout )*+'',(*$#'(-./('0.1(2%3.45+#2.%(2%'2&$()+4&'(
#0+#(0+6$(+().%'2'#$%#(*..7(+)4.''(#0$(8*+#3.45
9
:2&;$#'()+%(0+6$('0+&.1'(+%&(4./%&$&().4%$4'9
<+%(+*'.(=$(/'$&(+'(#$58*+#$(3.4($+)0(2#$5(2%(+(ListItem .4(
RecyclerView
9
<+%(=$(&4+;;$&(+%&(&4.88$&(34.5(>+*$##$9
RecyclerView ?@($332)2$%#(ListViewsA
B().%#+2%$4(3.4(&2'8*+-2%;(*+4;$(&+#+('$#'(#0+#()+%(=$(')4.**$&(6$4-(
$332)2$%#*-(=-(5+2%#+2%2%;(+(*252#$&(%/5=$4(.3(4$)-)*$&(62$1'
9
C$'#(#.(/'$(12#0(&+#+().**$)#2.%'(10.'$($*$5$%#'()0+%;$(+#(4/%#25$
=+'$&(.%(/'$4(+)#2.%(.4(%$#1.47($6$%#'
9
<+%(=$(&4+;;$&(+%&(&4.88$&(34.5(>+*$##$9
RecyclerView.LayoutManager layoutManager; 84.62&$'('252*+4(
3/%)#2.%+*2#-(#.(ListView
<+%(=$(+''2;%$&(2%($2#0$4(DEF(.4(G+6+
9
ViewHolder
H88*2$'(4$3$4$%)$'(#.(#0$(62$1'().%#+2%$&(2%(RecyclerView,(+%&(2'(#0$%(
8+''$&(#.(onBindViewHolder #.(+##+)0(&+#+(#.
9
:.47'(+'(+(=42&;$(=$#1$$%(#0$(DEF(+%&(G+6+9
I$&/)$'(#0$(%/5=$4(.3 findViewById() )+**'( 1$(%$$&(#.(5+7$,(+'(
#0$-(+4$($"8$%'26$
9
I$)-)*$4($"#$%&'(
RecyclerView.Adapter<RecylerAdapter.ViewHolder>
J%(#02'()+'$,('8$)232)(&+#+(#-8$(2'(+%-(#-8$(#0+#($"#$%&'(ViewHolder9
K'$(.3(#02'()*+''($*252%+#$'(4$8$+#$&(/'$(.3(findViewById 3.4(!L!IM(*2'#(
2#$5
9
N+6$'(+&&4$''$'(.=#+2%$&(=-(findViewById 2%(+(0+'0(5+8,(#0$%(.%*-(
/'$'(2#(+;+2%(10$%(+&&4$''$'(%$$&$&(+4$%O#(2%(0+'0(5+8
9
P$'#$&(2%'2&$(+&+8#$4()*+'',('2%)$(#0+#(2'(#0$(.%*-(8*+)$(2#(12**(=$(
4$3$4$%)$&
9
RecyclerView.Adapter
B(+()*+''()+**$&( Adapter %$'#$&(2%'2&$(#0$(RecyclerView )*+''
H))$8#'(*2'#(.3(2#$5'(34.5(MainActivity )*+'',(=/2*&'(CardViews +%&(=2%&'(
&+#+(#.(#0$5
B(02;0*-Q'8$)2+*2'$&()*+''(#0+#()+%(.%*-('$46$(+'(+%(+&+8#$4(#.(RecyclerView
R..&().&$(.4;+%2'+#2.%(2%(H>J(#.(%$'#(2#(2%'2&$(RecyclerView )*+''
P$$&'S
onCreateViewHolder, onBindViewHolder, getItemCount
ViewHolder '/=)*+''(?extends RecyclerView.ViewHolderA(
#.(258*$5$%#(T(.6$442&$(2#'()#.4
9
U+#+(VQQQQQ@(+&+8#$4(?'/=)*+''(.3(RecyclerView.AdapterA(VQQQQQ@(
RecyclerView
W(+&+8#$4(5$#0.&'(?)+**$&(4$8$+#$&*-(=-(2%#$4%+*(H>J().&$(#.(=/2*&(
RecyclerView *2'#A
onCreateViewHolder(ViewGroup parent, int viewType) Q
)4$+#$'(+(ViewHolder 2%'#+%)$(3.4(+(*2'#(2#$5
J'(8+''$&(+(4$3$4$%)$(#.(#0$(ViewGroup #0+#(12**().%#+2%(#0$(*2'#(
2#$5
X0$(*2'#(2#$5O'(*+-./#(2'(2%3*+#$&(2%#.(#0$(ViewGroup
ViewHolder 2%'#+%)$()4$+#$&(?/'2%;(4$3$4$%)$(#.(CardView
2%'#+%)$(8+''$&(2%#.(2#'()#.4A
<#.4('#.4$'(+**(4$3'(#.(12&;$#'(2%(CardView 2%'#+%)$(#0+#(12**(
%$$&(&+#+Y*2'#$%$4(=2%&2%;
§
Z8+4'$'(2#'(6+*/$'(#.(onBindViewHolder
9
>+''$&(#0$(%$1*-()4$+#$&(ViewHolder 2%'#+%)$(?8+4'$&(34.5(
onCreateViewHolderA(?3/**(.3(12&;$#(+&&4$''$'(3.4(+''.)2+#$&(
CardView 2%'#+%)$A(#;#(12#0(#0$(8.'2#2.%(2%(+&+8#$4O'(&+#+('$#(.3(
#0$(&+#+(#0$(L2$1[.*&$4(5/'#(=2%&(#.
:2&;$#'(2%(ViewHolder's +''.)2+#$&(CardView 2%'#+%)$(+4$(
=./%&(#.(&+#+
F2'#$%$4'()4$+#$&(+%&(+''2;%$&(+'(4$\/24$&(?/'/+**-(*2'#$%2%;(3.4(
onClickA
9
getItemCount() Q2%#$4%+*(H>J(/'$
P$$&(#.(.6$442&$(#.(#$**(H%&4.2&(10$#0$4(-./O4$().%'2&$42%;(#0$(
10.*$(+44+-(.4(+()$4#+2%(%/5=$4(.3(2#$5'(2%(#0$(+44+-(#.(=$(
&2'8*+-$&
9
Toolbar
?app:popupTheme:"@style/AppTheme.PopupOverlay"A()0+%;$'().*./4(
.3(.8#2.%(5$%/(8.8(/8(3.4(*$;2=2*2#-
N$#(#.(+)#(+'(H)#2.%(C+4(3.4(H)#262#-(12%&.1,(2%'#$+&(.3(/'2%;(ActionBar
?5.4$(&$#+2*'(2%(:$$7(]A
9
CoordinatorLayout
9
?android:fitsSystemWindows="true"A(5+7$'('/4$().58.%$%#(+**.1'(3.4(
'#+#/'(=+4
RecyclerView
?app:layout_behaviour="@string/appbar_scrolling_view_b
ehaviour"A(5/'#(0+6$,(23(%.#(RecyclerView ')4.**'(H88(C+4(324'#(
=$3.4$(')4.**2%;(RecyclerView
AppBarLayout
?android:theme="@style/AppTheme.AppBarOverlay"A(
2%6$4#'().*./42%;(#.(5+7$(#$"#(+%&(2).%'(2%(H88(C+4(5.4$(*$;2=*$( .%(
+%(25+;$(=+)7;4./%&^
L$4#2)+*(LinearLayout 102)0(258*$5$%#'(5+%-(.3(#0$(
3$+#/4$'(.3(EUO'(H88(C+4().%)$8#,(%+5$*-(')4.**2%;(;$'#/4$'
§
U$8$%&'(0$+62*-(.%(=$2%;(/'$&(+'(+(&24$)#()02*&(12#02%(+(
CoordinatorLayout
§
CollapsingToolbarLayout B(+(14+88$4(3.4(Toolbar
102)0(258*$5$%#'(+().**+8'2%;(+88(=+4
§
?2%2#2+*2'$&(2%'2&$(onCreateA
?android:layout_scrollFlags="scroll|enterAlwa
ys"A(')4.**(.3(')4$$%(&/42%;(/81+4&(')4.**(_(')4.**(.%(')4$$%(
&/42%;(&.1%1+4&(')4.**^(:2#0./#(#02'(H88(C+4(&.$'%O#(')4.**(
+#(+**,(RecyclerView 2%0$4$%#*-(')4.**'(.3)^
?android:fitsSystemWindows="true"A
U$'2;%$&(#.(=$(+(&24$)#()02*&(.3(AppBarLayout`
findViewById(R.id.collapsing_toolbar);
`
ImageView +%&(Toolbar %$'#$&`
<+4&U$5.aH88C+4bcdeN#/&$%#
F26$N#.)7H88N#/&$%#
E+'#$4U$#+2*bcdeN#/&$%#
Adapter
B(=2%&'(+88Q'8$)232)(&+#+(#.(62$1'(&2'8*+-$&(
?12#02%(+(RecyclerView 2%(#02'()+'$A
U+#+(%.45+**-('./4)$&(34.5(+(&+#+=+'$(62+(<>
What%does%this%code%do?
H(%$1(C/%&*$(2'('8$)232$&(+'(+%(+4;/5$%#^
H4;/5$%#'(2'(#.*&(#.(8/#(+('#42%;(#0+#(;4+='(#0$(f4+;5$%#(+4;/5$%#(4$84$'$%#2%;(#0$(
2#$5(JU(#0+#(#02'(f4+;5$%#(4$84$'$%#'^
H(%$1(f4+;5$%#(2'()4$+#$&(#.(=$(8*+)$&(2%(#0$(H)#262#-(*+-./#^
X0$(f4+;5$%#(2%8/#(2'(#0$('#42%;(34.5(=$3.4$^
getSupportFragmentManager() 2'()+**$&( #.(;$#(+(f4+;5$%#(E+%+;$4(/'2%;(#0$(
'/88.4#(*2=4+4-(H>J'^
beginTransaction() 2'()4$+#$&(#.()4$+#$(+(f4+;5$%#(#4+%'+)#2.%^
add() +&&'(f4+;5$%#(#.(L2$1^
<0+%;$'(+4$().552##$&^
gE+'#$4U$#+2*bcdeN#/&$%#h
I$'./4)$(32*$(\/+*232$4'
?$;(b(2#$5a*2'#^"5*(32*$'
&$3+/*#(4$'Y*+-./#9
4$'Y*+-./#Q1icc&8A9
B(+()$4#+2%().%&2#2.%Y4$'#4+2%#(#0+#(5/'#(=$(5$#(3.4(#0$('8$)232)(DEF(32*$(#.(=$(
.8$%$&
H*#$4%+#26$(4$'./4)$(\/+*232$4' ?+&&$&A
E<<(?5.=2*$()./%#4-().&$A(+%&(EP<(?5.=2*$(%$#1.47().&$A(Q5))Wec,(
5))WecQ5%)cc]
9
F+%;/+;$(+%&(4$;2.% Q$%,(34,($%Q4KN,(=T$%T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$('$%'2#26$9
m%*-(.%$(6+*/$(3.4($+)0(\/+*232$4(#-8$(2'('/88.4#$&(?&4+1+=*$Q4!NQ4fI(PmX(
8.''2=*$,(5/'#(0+6$(b(4$'./4)$(&24$)#.42$'A
9
Fragments
B(+('$*3Q).%#+2%$&,(5.&/*+4('$)#2.%(.3(+%(+88O'(KJ(+%&().44$'8.%&2%;(=$0+62./4(
#0+#()+%(=$($5=$&&$&(12#02%(+%(H)#262#-
B(4$84$'$%#(+(=$0+62./4Y8.4#2.%(.3(KJ(2%(+%(H)#262#-
[+6$(.1%(KJ(+%&(*+-./#9
F23$)-)*$(?ee()+**=+)7'A
onAttach()
onCreate()
getSupportFragmentManager .=#+2%'(34+;5$%#(5+%+;$4(
/'2%;('/88.4#(*2=4+4-(H>J'
§
B(+&&'(+(Fragment #.(84$62./'(*+-./#
beginTransaction()
N#+4#'(+(Fragment #4+%'+)#2.%(?&+#+(#4+%'+)#2.%A
®
`
replace?4$3$4$%)$(#.(?2&(.3A(View #0+#(12**().%#+2%(#0$(
34+;5$%#(gI^2&^aaah,(34+;5$%#(4$8*+)2%;(10+#$6$4(1+'(2%(
#0$(ViewA
I$8*+)$'(10+#$6$4(2'(2%(#0$('8$)232$&().%#+2%$4(
12#0(#02'(Fragment
®
K'$&(10$%(+(Fragment %$$&'(#.(=$()0+%;$&(+%&(
+&&$&(#.(#0$(=+)7'#+)7(&/42%;(#0$(H)#262#-O'(*23$
®
`
add(4$3$4$%)$(#.(?2&(.3A(View #0+#(12**().%#+2%(#0$(
34+;5$%#(gI^2&^aaah, Fragment =$2%;(+&&$&(#.(#0$(
View)
`
commit(); '+6$'(+**(&+#+,(4$+&-(#.(=$(*+/%)0$&(2%(
34+;5$%#(#.(+88*-()0+%;$'^
I$#/4%'(true 23('/))$''3/*(.4(false 23(3+2*$&
®
`
N)0$&/*$'(&+#+(#4+%'+)#2.%(#.(4/%(.%(+)#262#-O'(KJ(#04$+&(
?n5+2%n(#04$+&A(+'('..%(+'(#04$+&(2'(+=*$(#.(&.('.
`
J3(5/*#28*$()0+%;$'(5+&$(2%(+('2%;*$(#4+%'+)#2.%(+%&(
addToBackStack?34+;5$%#O'(#+;A(2'()+**$&,(+**()0+%;$'(
=$3.4$(commit() +4$(+&&$&(#.(=+)7('#+)7(+'(+('2%;*$(
#4+%'+)#2.%,(+%&(Back =/##.%(4$6$4'$'(#0$5(+**(#;#
`
onCreateView()
public class ItemDetailFragment extends
Fragment {
@Override
public View onCreateView
(LayoutInflater inflater, ViewGroup
container, Bundle savedInstanceState) {
return inflater.inflate
(R.layout.__, container, false);
}
}
onActivityCreated()
onStart()
onResume()
f4+;5$%#(2'(+)#26$
§
K'$4(%+62;+#$'(=+)71+4&'Yf4+;5$%#(2'(4$5.6$&(.4(4$8*+)$&`
mI(f4+;5$%#(+&&$&(#.(=+)7'#+)7,(#0$%(4$5.6$&(.4(4$8*+)$&`
onPause()
onStop()
onDestroyView()
onDestroy()
onDetach()
9
setArguments(Bundle arguments)
N+6$'(&+#+(#0+#(%$$&'(#.(=$(8+''$&(34.5(#0$(H)#262#-(#.(#0$(2%2#2+*2'2%;(
Fragment,('.(10$%(#0$(H)#262#-(4$*+/%)0$'(2%#.(#0$(Fragment,(#0$(
&+#+(12**(=$(#0$('+5$^
P.(%$$&(Bundle 23(%.(&+#+Y2%3.(345($"#$4%+*('./4)$(2'(4$\/24$&
H**.1'(Fragment +%&(2#'(H)#262#-(#.().55/%2)+#$(+%&(8+''(
&+#+(=$#1$$%($+)0(.#0$4
`
[under onCreate]
if(getArguments() != null) {
mParam1 =
getArguments().getString("key1");
}
9
g34.5(:$$7(oh9
findFragmentByTag(String tag)
X.(+))$''(%$1(34+;5$%#,(+&&(2#(#.(=+)7'#+)7(/'2%;(#0$(34+;5$%#O'(
/%2\/$(#+;(+'(+(4$3$4$%)$
X02'(12**(*..7(#04./;0(=+)7('#+)7(/%#2*(#0$(#+;(2'(3./%&
m%*-(8.''2=*$(84.=*$5(2'(5+2%#+2%2%;(#+;'(+%&(7$$82%;(#0$5(/%2\/$
9
X+;
E/'#(0+6$(=$$%(;26$%($2#0$4(10$%(2%3*+#$&(34.5(DEF
m4(+'('/88*2$&(10$%(+&&$&(2%(+(#4+%'+)#2.%
9
U233(=$#1$$%(H)#262#2$'(+%&(f4+;5$%#'S
f4+;5$%#'(5/'#(=$(%$'#$&(12#02%(+%(H)#262#-,()+%%.#(=$()4$+#$&(12#0./#(+%(
H)#262#-(#.('/88.4#(#0$5^
e^
[.1$6$4(H)#262#$'()+%%.#(=$(%$'#$&(12#02%(f4+;5$%#'^
E/*#28*$(34+;5$%#'()+%(4/%(.%(+('2%;*$(')4$$%(+#(#0$('+5$(#25$,(%.#(
8.''2=*$(3.4(H)#262#2$'^
b^
f4+;5$%#'()+%(=$(4$/'$&(#04./;0./#(5/*#28*$(H)#262#2$'^W^
f4+;5$%#'O(*23$)-)*$'(+4$(&$8$%&$%#(.%(#0$(H)#262#-(#0$-(+4$(%$'#$&(2%,(%.#(
).58*$#$*-(2%&$8$%&$%#(*27$(+%(H)#262#-O'^
]^
gF26$N#.)7H88N#/&$%#h
X.(4$#42$6$(&+#+(34.5(+(4$+*(1$=('$46$4(/'2%;([XX>(4$\/$'#'
H88('$%&'(4$\/$'#(#.(1$='2#$
0##8'SYY111^+*80+6+%#+;$^).Y\/$4-p
3/%)#2.%BXJE!aN!IJ!NaJPXIHUHMq'-5=.*BRmmRFq2%#$46+*B
er52%q+827$-B>KdR>LG<UMECCHsf
0##8'SYY111^+*80+6+%#+;$^). @@@(4$5.#$('$46$4
XJE!aN!IJ!NaJPXIHUHM(@@@(4$\24$&(3/%)#2.%
RmmRF(@@@( N#.)7(N-5=.*((?R..;*$A
er52%(@@@(2%#$46+*^(m#0$4(6+*/$'S(r,(ec,(Wc
>KdR>LG<UMECCHsf(@@@(H>J(7$-(?34$$(+%&(*23$#25$A
makeRequest(): +()+**=+)7(2%6.7$&(10$%(+(4$'8.%'$(.))/4'
<4$+#$'(6.**$-(8+)7+;$(2%(\/$/$
GNmP('#/33(;.$'(.%(#.($"#4+)#(&+#+(+%&(8/#(2%#.(+%(ArrayList
?dataItemsA
N$%&(&+#+(#.(4$)-)*$4(+&+8#$4 #.()4$+#$(62$1'(Q)4$+#$(%$1(.%$,(
setAdapter(new one)
H&&(4$\/$'#(#.(\/$/$
Week$6
X/$'&+-,( bi(E+-(bced eeScc
Unlock document

This preview shows pages 1-3 of the document.
Unlock all 8 pages and 3 million more documents.

Already have an account? Log in
CardView
!"#$%&'(FrameLayout )*+'',(*$#'(-./('0.1(2%3.45+#2.%(2%'2&$()+4&'(
#0+#(0+6$(+().%'2'#$%#(*..7(+)4.''(#0$(8*+#3.45
9
:2&;$#'()+%(0+6$('0+&.1'(+%&(4./%&$&().4%$4'
9
<+%(+*'.(=$(/'$&(+'(#$58*+#$(3.4($+)0(2#$5(2%(+(ListItem .4(
RecyclerView
9
<+%(=$(&4+;;$&(+%&(&4.88$&(34.5(>+*$##$
9
RecyclerView ?@($332)2$%#(ListViewsA
B().%#+2%$4(3.4(&2'8*+-2%;(*+4;$(&+#+('$#'(#0+#()+%(=$(')4.**$&(6$4-(
$332)2$%#*-(=-(5+2%#+2%2%;(+(*252#$&(%/5=$4(.3(4$)-)*$&(62$1'
9
C$'#(#.(/'$(12#0(&+#+().**$)#2.%'(10.'$($*$5$%#'()0+%;$(+#(4/%#25$
=+'$&(.%(/'$4(+)#2.%(.4(%$#1.47($6$%#'
9
<+%(=$(&4+;;$&(+%&(&4.88$&(34.5(>+*$##$9
RecyclerView.LayoutManager layoutManager; 84.62&$'('252*+4(
3/%)#2.%+*2#-(#.(ListView
<+%(=$(+''2;%$&(2%($2#0$4(DEF(.4(G+6+
9
ViewHolder
H88*2$'(4$3$4$%)$'(#.(#0$(62$1'().%#+2%$&(2%(RecyclerView,(+%&(2'(#0$%(
8+''$&(#.(onBindViewHolder #.(+##+)0(&+#+(#.
9
:.47'(+'(+(=42&;$(=$#1$$%(#0$(DEF(+%&(G+6+9
I$&/)$'(#0$(%/5=$4(.3 findViewById() )+**'( 1$(%$$&(#.(5+7$,(+'(
#0$-(+4$($"8$%'26$
9
I$)-)*$4($"#$%&'(
RecyclerView.Adapter<RecylerAdapter.ViewHolder>
J%(#02'()+'$,('8$)232)(&+#+(#-8$(2'(+%-(#-8$(#0+#($"#$%&'(ViewHolder9
K'$(.3(#02'()*+''($*252%+#$'(4$8$+#$&(/'$(.3(findViewById 3.4(!L!IM(*2'#(
2#$5
9
N+6$'(+&&4$''$'(.=#+2%$&(=-(findViewById 2%(+(0+'0(5+8,(#0$%(.%*-(
/'$'(2#(+;+2%(10$%(+&&4$''$'(%$$&$&(+4$%O#(2%(0+'0(5+8
9
P$'#$&(2%'2&$(+&+8#$4()*+'',('2%)$(#0+#(2'(#0$(.%*-(8*+)$(2#(12**(=$(
4$3$4$%)$&
9
RecyclerView.Adapter
B(+()*+''()+**$&( Adapter %$'#$&(2%'2&$(#0$(RecyclerView )*+''
H))$8#'(*2'#(.3(2#$5'(34.5(MainActivity )*+'',(=/2*&'(CardViews +%&(=2%&'(
&+#+(#.(#0$5
B(02;0*-Q'8$)2+*2'$&()*+''(#0+#()+%(.%*-('$46$(+'(+%(+&+8#$4(#.(RecyclerView
R..&().&$(.4;+%2'+#2.%(2%(H>J(#.(%$'#(2#(2%'2&$(RecyclerView )*+''
P$$&'S
onCreateViewHolder, onBindViewHolder, getItemCount
ViewHolder '/=)*+''(?extends RecyclerView.ViewHolderA(
#.(258*$5$%#(T(.6$442&$(2#'()#.4
9
U+#+(VQQQQQ@(+&+8#$4(?'/=)*+''(.3(RecyclerView.AdapterA(VQQQQQ@(
RecyclerView
W(+&+8#$4(5$#0.&'(?)+**$&(4$8$+#$&*-(=-(2%#$4%+*(H>J().&$(#.(=/2*&(
RecyclerView *2'#A
onCreateViewHolder(ViewGroup parent, int viewType) Q
)4$+#$'(+(ViewHolder 2%'#+%)$(3.4(+(*2'#(2#$5
J'(8+''$&(+(4$3$4$%)$(#.(#0$(ViewGroup #0+#(12**().%#+2%(#0$(*2'#(
2#$5
X0$(*2'#(2#$5O'(*+-./#(2'(2%3*+#$&(2%#.(#0$(ViewGroup
ViewHolder 2%'#+%)$()4$+#$&(?/'2%;(4$3$4$%)$(#.(CardView
2%'#+%)$(8+''$&(2%#.(2#'()#.4A
<#.4('#.4$'(+**(4$3'(#.(12&;$#'(2%(CardView 2%'#+%)$(#0+#(12**(
%$$&(&+#+Y*2'#$%$4(=2%&2%;
§
Z8+4'$'(2#'(6+*/$'(#.(onBindViewHolder
9
onBindViewHolder(VH holder, int position, List<Object>
payloads) Q=2%&'(+(*2'#(2#$5O'(&+#+(#.(2#'(ViewHolder 2%'#+%)$
>+''$&(#0$(%$1*-()4$+#$&(ViewHolder 2%'#+%)$(?8+4'$&(34.5(
onCreateViewHolderA(?3/**(.3(12&;$#(+&&4$''$'(3.4(+''.)2+#$&(
CardView 2%'#+%)$A(#;#(12#0(#0$(8.'2#2.%(2%(+&+8#$4O'(&+#+('$#(.3(
#0$(&+#+(#0$(L2$1[.*&$4(5/'#(=2%&(#.
:2&;$#'(2%(ViewHolder's +''.)2+#$&(CardView 2%'#+%)$(+4$(
=./%&(#.(&+#+
F2'#$%$4'()4$+#$&(+%&(+''2;%$&(+'(4$\/24$&(?/'/+**-(*2'#$%2%;(3.4(
onClickA
9
getItemCount() Q2%#$4%+*(H>J(/'$
P$$&(#.(.6$442&$(#.(#$**(H%&4.2&(10$#0$4(-./O4$().%'2&$42%;(#0$(
10.*$(+44+-(.4(+()$4#+2%(%/5=$4(.3(2#$5'(2%(#0$(+44+-(#.(=$(
&2'8*+-$&
9
Toolbar
?app:popupTheme:"@style/AppTheme.PopupOverlay"A()0+%;$'().*./4(
.3(.8#2.%(5$%/(8.8(/8(3.4(*$;2=2*2#-
N$#(#.(+)#(+'(H)#2.%(C+4(3.4(H)#262#-(12%&.1,(2%'#$+&(.3(/'2%;(ActionBar
?5.4$(&$#+2*'(2%(:$$7(]A
9
CoordinatorLayout
9
?android:fitsSystemWindows="true"A(5+7$'('/4$().58.%$%#(+**.1'(3.4(
'#+#/'(=+4
RecyclerView
?app:layout_behaviour="@string/appbar_scrolling_view_b
ehaviour"A(5/'#(0+6$,(23(%.#(RecyclerView ')4.**'(H88(C+4(324'#(
=$3.4$(')4.**2%;(RecyclerView
AppBarLayout
?android:theme="@style/AppTheme.AppBarOverlay"A(
2%6$4#'().*./42%;(#.(5+7$(#$"#(+%&(2).%'(2%(H88(C+4(5.4$(*$;2=*$( .%(
+%(25+;$(=+)7;4./%&^
L$4#2)+*(LinearLayout 102)0(258*$5$%#'(5+%-(.3(#0$(
3$+#/4$'(.3(EUO'(H88(C+4().%)$8#,(%+5$*-(')4.**2%;(;$'#/4$'
§
U$8$%&'(0$+62*-(.%(=$2%;(/'$&(+'(+(&24$)#()02*&(12#02%(+(
CoordinatorLayout
§
CollapsingToolbarLayout B(+(14+88$4(3.4(Toolbar
102)0(258*$5$%#'(+().**+8'2%;(+88(=+4
§
?2%2#2+*2'$&(2%'2&$(onCreateA
?android:layout_scrollFlags="scroll|enterAlwa
ys"A(')4.**(.3(')4$$%(&/42%;(/81+4&(')4.**(_(')4.**(.%(')4$$%(
&/42%;(&.1%1+4&(')4.**^(:2#0./#(#02'(H88(C+4(&.$'%O#(')4.**(
+#(+**,(RecyclerView 2%0$4$%#*-(')4.**'(.3)^
?android:fitsSystemWindows="true"A
U$'2;%$&(#.(=$(+(&24$)#()02*&(.3(AppBarLayout
`
findViewById(R.id.collapsing_toolbar);
`
ImageView +%&(Toolbar %$'#$&
`
<+4&U$5.aH88C+4bcdeN#/&$%#
F26$N#.)7H88N#/&$%#
E+'#$4U$#+2*bcdeN#/&$%#
Adapter
B(=2%&'(+88Q'8$)232)(&+#+(#.(62$1'(&2'8*+-$&(
?12#02%(+(RecyclerView 2%(#02'()+'$A
U+#+(%.45+**-('./4)$&(34.5(+(&+#+=+'$(62+(<>
What%does%this%code%do?
H(%$1(C/%&*$(2'('8$)232$&(+'(+%(+4;/5$%#^
H4;/5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(.1%(KJ(+%&(*+-./#9
F23$)-)*$(?ee()+**=+)7'A
onAttach()
onCreate()
getSupportFragmentManager .=#+2%'(34+;5$%#(5+%+;$4(
/'2%;('/88.4#(*2=4+4-(H>J'
§
B(+&&'(+(Fragment #.(84$62./'(*+-./#
beginTransaction()
N#+4#'(+(Fragment #4+%'+)#2.%(?&+#+(#4+%'+)#2.%A
®
`
replace?4$3$4$%)$(#.(?2&(.3A(View #0+#(12**().%#+2%(#0$(
34+;5$%#(gI^2&^aaah,(34+;5$%#(4$8*+)2%;(10+#$6$4(1+'(2%(
#0$(ViewA
I$8*+)$'(10+#$6$4(2'(2%(#0$('8$)232$&().%#+2%$4(
12#0(#02'(Fragment
®
K'$&(10$%(+(Fragment %$$&'(#.(=$()0+%;$&(+%&(
+&&$&(#.(#0$(=+)7'#+)7(&/42%;(#0$(H)#262#-O'(*23$
®
`
add(4$3$4$%)$(#.(?2&(.3A(View #0+#(12**().%#+2%(#0$(
34+;5$%#(gI^2&^aaah, Fragment =$2%;(+&&$&(#.(#0$(
View)
`
commit(); '+6$'(+**(&+#+,(4$+&-(#.(=$(*+/%)0$&(2%(
34+;5$%#(#.(+88*-()0+%;$'^
I$#/4%'(true 23('/))$''3/*(.4(false 23(3+2*$&
®
`
N)0$&/*$'(&+#+(#4+%'+)#2.%(#.(4/%(.%(+)#262#-O'(KJ(#04$+&(
?n5+2%n(#04$+&A(+'('..%(+'(#04$+&(2'(+=*$(#.(&.('.
`
J3(5/*#28*$()0+%;$'(5+&$(2%(+('2%;*$(#4+%'+)#2.%(+%&(
addToBackStack?34+;5$%#O'(#+;A(2'()+**$&,(+**()0+%;$'(
=$3.4$(commit() +4$(+&&$&(#.(=+)7('#+)7(+'(+('2%;*$(
#4+%'+)#2.%,(+%&(Back =/##.%(4$6$4'$'(#0$5(+**(#;#
`
onCreateView()
public class ItemDetailFragment extends
Fragment {
@Override
public View onCreateView
(LayoutInflater inflater, ViewGroup
container, Bundle savedInstanceState) {
return inflater.inflate
(R.layout.__, container, false);
}
}
onActivityCreated()
onStart()
onResume()
f4+;5$%#(2'(+)#26$
§
K'$4(%+62;+#$'(=+)71+4&'Yf4+;5$%#(2'(4$5.6$&(.4(4$8*+)$&`
mI(f4+;5$%#(+&&$&(#.(=+)7'#+)7,(#0$%(4$5.6$&(.4(4$8*+)$&`
onPause()
onStop()
onDestroyView()
onDestroy()
onDetach()
9
setArguments(Bundle arguments)
N+6$'(&+#+(#0+#(%$$&'(#.(=$(8+''$&(34.5(#0$(H)#262#-(#.(#0$(2%2#2+*2'2%;(
Fragment,('.(10$%(#0$(H)#262#-(4$*+/%)0$'(2%#.(#0$(Fragment,(#0$(
&+#+(12**(=$(#0$('+5$^
P.(%$$&(Bundle 23(%.(&+#+Y2%3.(345($"#$4%+*('./4)$(2'(4$\/24$&
H**.1'(Fragment +%&(2#'(H)#262#-(#.().55/%2)+#$(+%&(8+''(
&+#+(=$#1$$%($+)0(.#0$4
`
[under onCreate]
if(getArguments() != null) {
mParam1 =
getArguments().getString("key1");
}
9
g34.5(:$$7(oh9
findFragmentByTag(String tag)
X.(+))$''(%$1(34+;5$%#,(+&&(2#(#.(=+)7'#+)7(/'2%;(#0$(34+;5$%#O'(
/%2\/$(#+;(+'(+(4$3$4$%)$
X02'(12**(*..7(#04./;0(=+)7('#+)7(/%#2*(#0$(#+;(2'(3./%&
m%*-(8.''2=*$(84.=*$5(2'(5+2%#+2%2%;(#+;'(+%&(7$$82%;(#0$5(/%2\/$
9
X+;
E/'#(0+6$(=$$%(;26$%($2#0$4(10$%(2%3*+#$&(34.5(DEF
m4(+'('/88*2$&(10$%(+&&$&(2%(+(#4+%'+)#2.%
9
U233(=$#1$$%(H)#262#2$'(+%&(f4+;5$%#'S
f4+;5$%#'(5/'#(=$(%$'#$&(12#02%(+%(H)#262#-,()+%%.#(=$()4$+#$&(12#0./#(+%(
H)#262#-(#.('/88.4#(#0$5^
e^
[.1$6$4(H)#262#$'()+%%.#(=$(%$'#$&(12#02%(f4+;5$%#'^
E/*#28*$(34+;5$%#'()+%(4/%(.%(+('2%;*$(')4$$%(+#(#0$('+5$(#25$,(%.#(
8.''2=*$(3.4(H)#262#2$'^
b^
f4+;5$%#'()+%(=$(4$/'$&(#04./;0./#(5/*#28*$(H)#262#2$'^W^
f4+;5$%#'O(*23$)-)*$'(+4$(&$8$%&$%#(.%(#0$(H)#262#-(#0$-(+4$(%$'#$&(2%,(%.#(
).58*$#$*-(2%&$8$%&$%#(*27$(+%(H)#262#-O'^
]^
gF26$N#.)7H88N#/&$%#h
X.(4$#42$6$(&+#+(34.5(+(4$+*(1$=('$46$4(/'2%;([XX>(4$\/$'#'
H88('$%&'(4$\/$'#(#.(1$='2#$
0##8'SYY111^+*80+6+%#+;$^).Y\/$4-p
3/%)#2.%BXJE!aN!IJ!NaJPXIHUHMq'-5=.*BRmmRFq2%#$46+*B
er52%q+827$-B>KdR>LG<UMECCHsf
0##8'SYY111^+*80+6+%#+;$^). @@@(4$5.#$('$46$4
XJE!aN!IJ!NaJPXIHUHM(@@@(4$\24$&(3/%)#2.%
RmmRF(@@@( N#.)7(N-5=.*((?R..;*$A
er52%(@@@(2%#$46+*^(m#0$4(6+*/$'S(r,(ec,(Wc
>KdR>LG<UMECCHsf(@@@(H>J(7$-(?34$$(+%&(*23$#25$A
makeRequest(): +()+**=+)7(2%6.7$&(10$%(+(4$'8.%'$(.))/4'
<4$+#$'(6.**$-(8+)7+;$(2%(\/$/$
GNmP('#/33(;.$'(.%(#.($"#4+)#(&+#+(+%&(8/#(2%#.(+%(ArrayList
?dataItemsA
N$%&(&+#+(#.(4$)-)*$4(+&+8#$4 #.()4$+#$(62$1'(Q)4$+#$(%$1(.%$,(
setAdapter(new one)
H&&(4$\/$'#(#.(\/$/$
Week$6
X/$'&+-,( bi(E+-(bced eeScc
Unlock document

This preview shows pages 1-3 of the document.
Unlock all 8 pages and 3 million more documents.

Already have an account? Log in

Document Summary

= container for displaying large data sets that can be scrolled very efficiently by maintaining a limited number of recycled views. Best to use with data collections whose elements change at runtime based on user action or network events. Can be assigned in either xml or java. Applies references to the views contained in recyclerview, and is then passed to onbindviewholder to attach data to. Works as a bridge between the xml and java. Reduces the number of findviewbyid() calls we need to make, as they are expensive. In this case, specific data type is any type that extends viewholder. Use of this class eliminates repeated use of findviewbyid for every list item. Saves addresses obtained by findviewbyid in a hash map, then only uses it again when addresses needed aren"t in hash map. Nested inside adapter class, since that is the only place it will be referenced. = a class called adapter nested inside the recyclerview class.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers