1313
1414import com .commit451 .adapterlayout .AdapterLinearLayout ;
1515
16- import butterknife .Bind ;
16+ import butterknife .BindView ;
1717import butterknife .ButterKnife ;
1818import butterknife .OnClick ;
1919
2020public class MainActivity extends AppCompatActivity {
2121
22- @ Bind (R .id .root )
22+ @ BindView (R .id .root )
2323 ViewGroup root ;
24- @ Bind (R .id .toolbar )
24+ @ BindView (R .id .toolbar )
2525 Toolbar toolbar ;
26- @ Bind (R .id .adapter_layout )
26+ @ BindView (R .id .adapter_layout )
2727 AdapterLinearLayout adapterLinearLayout ;
28- @ Bind (R .id .animate_layout_changes )
28+ @ BindView (R .id .animate_layout_changes )
2929 CheckBox checkBoxAnimateLayoutChanges ;
3030
3131 CheeseAdapter adapter ;
3232
33- private CheeseAdapter .Listener mListener = new CheeseAdapter .Listener () {
33+ private CheeseAdapter .Listener listener = new CheeseAdapter .Listener () {
3434 @ Override
3535 public void onItemClicked (Cheese cheese ) {
36- Snackbar .make (root , cheese .getName () + " clicked" , Snackbar .LENGTH_SHORT )
36+ Snackbar .make (root , cheese .name + " clicked" , Snackbar .LENGTH_SHORT )
3737 .show ();
3838 }
3939 };
@@ -63,9 +63,16 @@ void onChangeAll() {
6363 adapter .changeAll ();
6464 }
6565
66+ @ OnClick (R .id .set_to_5 )
67+ void onSetTo5Clicked () {
68+ adapter .setData (Cheeses .getRandomCheeses (5 ));
69+ }
70+
6671 @ OnClick (R .id .new_adapter )
6772 void onNewAdapterClicked () {
68- adapter .setData (Cheeses .getRandomCheeses (5 ));
73+ adapterLinearLayout .setAdapter (null );
74+ adapter = new CheeseAdapter (listener );
75+ adapterLinearLayout .setAdapter (adapter );
6976 }
7077
7178 @ Override
@@ -79,19 +86,14 @@ protected void onCreate(Bundle savedInstanceState) {
7986 @ Override
8087 public boolean onMenuItemClick (MenuItem item ) {
8188 switch (item .getItemId ()) {
82- case R .id .action_custom_adapter_layout :
83- startActivity (new Intent (MainActivity .this , CustomAdapterLayoutActivity .class ));
89+ case R .id .action_adapter_flow_layout :
90+ startActivity (new Intent (MainActivity .this , AdapterFlowLayoutActivity .class ));
8491 return true ;
8592 }
8693 return false ;
8794 }
8895 });
89- adapter = new CheeseAdapter (new CheeseAdapter .Listener () {
90- @ Override
91- public void onItemClicked (Cheese cheese ) {
92-
93- }
94- });
96+ adapter = new CheeseAdapter (listener );
9597 adapterLinearLayout .setAdapter (adapter );
9698
9799 checkBoxAnimateLayoutChanges .setOnCheckedChangeListener (new CompoundButton .OnCheckedChangeListener () {
@@ -106,7 +108,5 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
106108 }
107109 });
108110 checkBoxAnimateLayoutChanges .setChecked (true );
109-
110- adapter .setData (Cheeses .getRandomCheeses (10 ));
111111 }
112112}
0 commit comments