问题
I make a fragment in which I attach a recycler view with dummy data but when I include this fragment in my slide up a panel which is in the main activity so the main activity slider data show but in fragment data it says recyclerview adapter not found it's skipped. kindly tell me what is an issue
Main activity with Slidepanel layout.xml
<com.sothree.slidinguppanel.SlidingUpPanelLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:sothree="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/slider_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:umanoPanelHeight="68dp"
sothree:umanoShadowHeight="4dp"
tools:context=".sliderFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="@+id/slider_main"
layout="@layout/fragment_slider"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="@+id/slideToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
sothree:titleTextColor="@color/colorWhite" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/slider_recycle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:listitem="@layout/review_design" />
</LinearLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {
Toolbar toolbar;
reviewAdapt adaptView;
SlidingUpPanelLayout slidingUpPanelLayout;
RecyclerView recyclerOverView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findview();
}
private void findview() {
recyclerOverView = findViewById(R.id.slider_recycle);
toolbar = findViewById(R.id.slideToolbar);
slidingUpPanelLayout = findViewById(R.id.slider_drawer);
populateList();
list();
}
private void list() {
slidingUpPanelLayout.addPanelSlideListener(new SlidingUpPanelLayout.PanelSlideListener() {
@Override
public void onPanelSlide(View panel, float slideOffset) {
Log.i(TAG, "onPanelSlide, offset " + slideOffset);
}
@Override
public void onPanelStateChanged(View panel, SlidingUpPanelLayout.PanelState previousState, SlidingUpPanelLayout.PanelState newState) {
Log.i(TAG, "onPanelStateChanged " + newState);
}
});
slidingUpPanelLayout.setFadeOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
slidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED);
}
});
}
private void populateList() {
List<reviewModel> reviewModelList = new ArrayList<>();
for (int i = 1; i < 20; i++) {
int imges = R.drawable.ic_userlogin;
String names = " Name is " + i;
String dates = " Dates is " + i;
String detail = " details about is " + i;
reviewModel models = new reviewModel(names, dates, detail, 4, imges);
reviewModelList.add(models);
}
setupRecycle(reviewModelList);
}
private void setupRecycle(List<reviewModel> reviewModelList) {
adaptView = new reviewAdapt(this, reviewModelList, reviewModelList.size());
LinearLayoutManager layout = new LinearLayoutManager(this);
layout.setSmoothScrollbarEnabled(true);
recyclerOverView.setLayoutManager(layout);
recyclerOverView.setHasFixedSize(true);
recyclerOverView.setAdapter(adaptView);
Log.d("adpater","show");
}}
SliderFragment.xml
<androidx.drawerlayout.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/salon_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/salonToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorGrey"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:titleTextColor="@color/colorWhite" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/salon_tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorGrey"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/salonToolbar" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/salon_tabLayout"
tools:listitem="@layout/review_design" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/call_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|end"
android:paddingBottom="@dimen/_16sdp"
android:src="@drawable/ic_call"
android:tint="@color/colorBlack"
android:translationY="-8dp"
app:backgroundTint="@color/colorOrange"
app:layout_anchor="@id/msg_fab"
app:layout_anchorGravity="top" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/msg_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|end"
android:layout_margin="@dimen/_8sdp"
android:layout_marginBottom="@dimen/_16sdp"
android:src="@drawable/ic_message"
android:tint="@color/colorBlack"
android:translationY="-8dp"
app:backgroundTint="@color/colorOrange"
app:layout_anchor="@id/extend_fab"
app:layout_anchorGravity="top" />
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/extend_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/_8sdp"
android:text="@string/extended"
app:backgroundTint="@color/colorOrange"
app:cornerRadius="@dimen/_30sdp"
app:icon="@drawable/ic_add"
app:iconGravity="start" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.navigation.NavigationView
android:id="@+id/salonNavigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/header_salon"
app:menu="@menu/salon_menu" />
</androidx.drawerlayout.widget.DrawerLayout>
SlideFragment.java
public class sliderFragment extends Fragment {
reviewAdapt adaptOverView;
RecyclerView recyclerOverView;
Toolbar toolbar;
Fragment slider;
TabLayout tabLayout;
ActionBarDrawerToggle toggle;
DrawerLayout drawer;
boolean isClick=false;
NavigationView navigationView;
FloatingActionButton msgFab, callFab;
ExtendedFloatingActionButton exFab;
public sliderFragment() {
// Required empty public constructor
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_slider, container, false);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
findview(view);
}
private void findview(View view) {
toolbar = view.findViewById(R.id.salonToolbar);
tabLayout = view.findViewById(R.id.salon_tabLayout);
drawer = view.findViewById(R.id.salon_drawer);
msgFab = view.findViewById(R.id.msg_fab);
callFab = view.findViewById(R.id.call_fab);
exFab = view.findViewById(R.id.extend_fab);
recyclerOverView = view.findViewById(R.id.recyclerList);
navigationView = view.findViewById(R.id.salonNavigation);
((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
showToggle();
populateList();
fabExtension();
}
private void fabExtension() {
exFab.shrink();
msgFab.hide();
callFab.hide();
exFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isClick) {
msgFab.setVisibility(View.GONE);
callFab.setVisibility(View.GONE);
isClick = false;
} else {
msgFab.setVisibility(View.VISIBLE);
callFab.setVisibility(View.VISIBLE);
isClick = true;
}
}
});
}
private void showToggle() {
toggle = new ActionBarDrawerToggle(getActivity(), drawer, toolbar, R.string.open,
R.string.close);
drawer.addDrawerListener(toggle);
toggle.syncState();
toggle.getDrawerArrowDrawable().setColor(getResources().getColor(R.color.colorWhite));
navigationView.setNavigationItemSelectedListener(new
NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.about_salon:
Toast.makeText(getContext(), "About Item Click", Toast.LENGTH_SHORT).show();
drawer.closeDrawer(GravityCompat.START);
break;
case R.id.home_salon:
Toast.makeText(getContext(), "Home Item Click", Toast.LENGTH_SHORT).show();
drawer.closeDrawer(GravityCompat.START);
break;
case R.id.details_salon:
Toast.makeText(getContext(), "Details Item Click", Toast.LENGTH_SHORT).show();
drawer.closeDrawer(GravityCompat.START);
break;
case R.id.setting_salon:
Toast.makeText(getContext(), "Setting Item Click", Toast.LENGTH_SHORT).show();
drawer.closeDrawer(GravityCompat.START);
break;
default:
break;
}
return false;
}
});
}
private void populateList() {
List<reviewModel> reviewList = new ArrayList<>();
for (int i = 1; i < 20; i++) {
int imges = R.drawable.ic_userlogin;
String names = "User Name is " + i;
String dates = "New Dates is " + i;
String detail = "User details about is " + i;
reviewModel models = new reviewModel(names, dates, detail, 4, imges);
reviewList.add(models);
}
setupRecycle(reviewList);
}
private void setupRecycle(List<reviewModel> reviewList) {
adaptOverView = new reviewAdapt(getContext(), reviewList, reviewList.size());
LinearLayoutManager layout = new LinearLayoutManager(getContext());
layout.setSmoothScrollbarEnabled(true);
recyclerOverView.setLayoutManager(layout);
recyclerOverView.setHasFixedSize(true);
recyclerOverView.setAdapter(adaptOverView);
recyclerOverView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if (dy < 0)
exFab.shrink();
else if (dy > 0)
exFab.extend();
}
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
}
});
}}
来源:https://stackoverflow.com/questions/64259818/adapter-not-found-skipped-in-fragment-with-navigation-drawer-and-appbar