22
33import android .graphics .Rect ;
44import android .os .Bundle ;
5- import android .support .annotation .NonNull ;
6- import android .support .design .widget .BottomNavigationView ;
7- import android .support .v7 .app .AppCompatActivity ;
8- import android .support .v7 .widget .RecyclerView ;
95import android .view .MenuItem ;
106import android .view .View ;
117
8+ import androidx .annotation .NonNull ;
9+ import androidx .appcompat .app .AppCompatActivity ;
10+ import androidx .recyclerview .widget .RecyclerView ;
11+
12+ import com .google .android .material .bottomnavigation .BottomNavigationView ;
1213import com .xiaofeng .flowlayoutmanager .Alignment ;
1314import com .xiaofeng .flowlayoutmanager .FlowLayoutManager ;
1415
16+ import java .util .Objects ;
17+
1518public class MainActivity extends AppCompatActivity {
1619
1720 RecyclerView recyclerView ;
1821 FlowLayoutManager flowLayoutManager ;
1922 RecyclerView .ItemDecoration itemDecoration = new RecyclerView .ItemDecoration () {
2023 @ Override
21- public void getItemOffsets (Rect outRect , View view , RecyclerView parent , RecyclerView .State state ) {
24+ public void getItemOffsets (@ NonNull Rect outRect , @ NonNull View view , @ NonNull RecyclerView parent , @ NonNull RecyclerView .State state ) {
2225 super .getItemOffsets (outRect , view , parent , state );
2326 outRect .set (5 , 5 , 5 , 5 );
2427 }
@@ -35,7 +38,7 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
3538 flowLayoutManager .setAutoMeasureEnabled (true );
3639
3740 recyclerView .setLayoutManager (flowLayoutManager );
38- recyclerView .getAdapter ().notifyDataSetChanged ();
41+ Objects . requireNonNull ( recyclerView .getAdapter () ).notifyDataSetChanged ();
3942
4043 return true ;
4144 case R .id .navigation_center :
@@ -66,7 +69,6 @@ protected void onCreate(Bundle savedInstanceState) {
6669
6770 BottomNavigationView navigation = findViewById (R .id .navigation );
6871 navigation .setOnNavigationItemSelectedListener (mOnNavigationItemSelectedListener );
69-
7072 recyclerView = findViewById (R .id .list );
7173 flowLayoutManager = new FlowLayoutManager ().setAlignment (Alignment .LEFT );
7274 flowLayoutManager .setAutoMeasureEnabled (true );
@@ -75,7 +77,5 @@ protected void onCreate(Bundle savedInstanceState) {
7577 recyclerView .getAdapter ().notifyDataSetChanged ();
7678 recyclerView .addItemDecoration (itemDecoration );
7779
78-
7980 }
80-
8181}
0 commit comments