11package com .commit451 .adapterlayout .sample ;
22
33import android .os .Bundle ;
4- import android .support .v7 .app .AppCompatActivity ;
5- import android .support .v7 .widget .Toolbar ;
64import android .view .View ;
75import android .widget .Toast ;
86
97import com .commit451 .adapterflowlayout .AdapterFlowLayout ;
108
119import java .util .ArrayList ;
1210
13- import butterknife .BindView ;
14- import butterknife .ButterKnife ;
15- import butterknife .OnClick ;
11+ import androidx .appcompat .app .AppCompatActivity ;
12+ import androidx .appcompat .widget .Toolbar ;
1613
1714public class AdapterFlowLayoutActivity extends AppCompatActivity {
1815
19- @ BindView (R .id .toolbar )
2016 Toolbar toolbar ;
21- @ BindView (R .id .adapter_layout )
2217 AdapterFlowLayout adapterFlowLayout ;
2318
2419 CheeseAdapter adapter ;
@@ -31,28 +26,12 @@ public void onItemClicked(Cheese cheese) {
3126 }
3227 };
3328
34- @ OnClick (R .id .add_cheese )
35- void onAddCheeseClicked () {
36- adapter .add (Cheeses .getRandomCheese ());
37- }
38-
39- @ OnClick (R .id .remove_cheese )
40- void onRemoveCheeseClicked () {
41- adapter .removeLast ();
42- }
43-
44- @ OnClick (R .id .new_adapter )
45- void onNewAdapterClicked () {
46- adapterFlowLayout .setAdapter (null );
47- adapter = new CheeseAdapter (listener );
48- adapterFlowLayout .setAdapter (adapter );
49- }
50-
5129 @ Override
5230 protected void onCreate (Bundle savedInstanceState ) {
5331 super .onCreate (savedInstanceState );
5432 setContentView (R .layout .activity_custom_adapter_layout );
55- ButterKnife .bind (this );
33+ toolbar = findViewById (R .id .toolbar );
34+ adapterFlowLayout = findViewById (R .id .adapter_layout );
5635 toolbar .setNavigationIcon (R .drawable .ic_arrow_back_24dp );
5736 toolbar .setNavigationOnClickListener (new View .OnClickListener () {
5837 @ Override
@@ -62,6 +41,24 @@ public void onClick(View v) {
6241 });
6342 adapter = new CheeseAdapter (listener );
6443 adapterFlowLayout .setAdapter (adapter );
44+
45+ findViewById (R .id .add_cheese ).setOnClickListener (new View .OnClickListener () {
46+ @ Override public void onClick (View v ) {
47+ adapter .add (Cheeses .getRandomCheese ());
48+ }
49+ });
50+ findViewById (R .id .remove_cheese ).setOnClickListener (new View .OnClickListener () {
51+ @ Override public void onClick (View v ) {
52+ adapter .removeLast ();
53+ }
54+ });
55+ findViewById (R .id .new_adapter ).setOnClickListener (new View .OnClickListener () {
56+ @ Override public void onClick (View v ) {
57+ adapterFlowLayout .setAdapter (null );
58+ adapter = new CheeseAdapter (listener );
59+ adapterFlowLayout .setAdapter (adapter );
60+ }
61+ });
6562 loadCheeses ();
6663 }
6764
0 commit comments