gpt4 book ai didi

android-viewpager - TabLayout,BottomSheetDialogFragment中的ViewPager

转载 作者:行者123 更新时间:2023-12-03 10:11:31 27 4
gpt4 key购买 nike

我想要 Bottom Sheet ,它在viewpager中显示两个片段。我将两个Fragments与FragmentPagerAdapter和BottomSheetDialogFragment一起使用来构建对话框。

我的问题是在viewPager中,第二个片段recyclerview不滚动。

Image of my application displaying

Recyclerview适配器

public class LigneListAdapter extends RecyclerView.Adapter<LigneListAdapter.ListViewHolder> {

Context context;
List<Ligne> lignes = new ArrayList<>();
LayoutInflater inflater;
ListListener listener;

public LigneListAdapter(Context context, List<Ligne> list) {

this.context = context;
this.lignes = list;
//this.listener= (ListListener) context;
inflater = LayoutInflater.from(context);


}

@Override
public ListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

View convertView = inflater.inflate(R.layout.ligne_list_row, parent, false);
ListViewHolder viewHolder = new ListViewHolder(convertView);
return viewHolder;
}

@Override
public void onBindViewHolder(ListViewHolder holder, int position) {


holder.ligne_icon.setTag(position);
holder.ligne_name.setText(lignes.get(position).getNomLigne());

holder.ligne_name.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// listener.nameToChnge(lignes.get((Integer) v.getTag()).getId());


}
});

}

@Override
public int getItemCount() {
return lignes.size();
}

class ListViewHolder extends RecyclerView.ViewHolder {
TextView ligne_name;
ImageView ligne_icon;

public ListViewHolder(View itemView) {
super(itemView);

ligne_name = (TextView) itemView.findViewById(R.id.ligne_name);
ligne_icon= (ImageView) itemView.findViewById(R.id.ligne_icon);

}
}
}

我的第一个片段代码(与第二个片段相同)
public class LigneFragment extends Fragment implements ListListener {

private RecyclerView recyclerView;
private LigneDAO ligneDAO ;
private LigneListAdapter adapter;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// super.onCreateView(inflater,container,savedInstanceState);

View v = inflater.inflate(R.layout.ligne_fragment_list_view, null);
ligneDAO = new LigneDAO(getContext());
ligneDAO.open();

recyclerView = (RecyclerView) v.findViewById(R.id.recycler_list_view);
adapter = new LigneListAdapter(getContext(), ligneDAO.getAllLignes());
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
ligneDAO.close();
return v;
}

@Override
public void nameToChnge(String name) {

}

@Override
public void getStationSelected(Station station) {

}
}

FragmentPagerAdapter
public class PagerAdapter extends FragmentPagerAdapter {

public PagerAdapter(FragmentManager fm) {
super(fm);
}

@Override
public Fragment getItem(int position) {

Fragment frag=null;
switch (position){
case 0:
frag=new LigneFragment();
break;
case 1:
frag=new StationFragment();
break;
}
return frag;
}

@Override
public int getCount() {
return 2;
}

@Override
public CharSequence getPageTitle(int position) {
String title=" ";
switch (position){
case 0:
title="Lignes";
break;
case 1:
title="Stations";
break;
}

return title;
}
}

BottomSheetDialogFragment
public class AlsaBottomDialogFragment   extends BottomSheetDialogFragment {


private static final String TAB_POSITION = "tab_position";

private PagerAdapter adapter;
private ViewPager viewPager;
private TabLayout tabLayout;

private LinearLayoutManager mLinearLayoutManager;
private AlsaRecyclerAdapter mAdapter;

public AlsaBottomDialogFragment(){

}


private BottomSheetBehavior.BottomSheetCallback mBottomSheetBehaviorCallback = new BottomSheetBehavior.BottomSheetCallback() {

@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
if (newState == BottomSheetBehavior.STATE_HIDDEN) {
dismiss();
}
}

@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
}
};

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

View root = inflater.inflate(R.layout.bottom_sheet, container);
tabLayout = (TabLayout) root.findViewById(R.id.tablayout);
viewPager = (ViewPager) root.findViewById(R.id.viewpager);

adapter = new PagerAdapter(getChildFragmentManager());
viewPager.setAdapter(adapter);
tabLayout.post(new Runnable() {
@Override
public void run() {
tabLayout.setupWithViewPager(viewPager);
}
});
return root;
}


@Override
public void onViewCreated(View contentView, @Nullable Bundle savedInstanceState) {
super.onViewCreated(contentView, savedInstanceState);
}

@Override
public void setupDialog(Dialog dialog, int style) {
super.setupDialog(dialog, style);
View contentView = View.inflate(getContext(), R.layout.bottom_sheet, null);
dialog.setContentView(contentView);
CoordinatorLayout.LayoutParams layoutParams =
(CoordinatorLayout.LayoutParams) ((View) contentView.getParent()).getLayoutParams();
CoordinatorLayout.Behavior behavior = layoutParams.getBehavior();
if (behavior != null && behavior instanceof BottomSheetBehavior) {
((BottomSheetBehavior) behavior).setBottomSheetCallback(mBottomSheetBehaviorCallback);
}

}

}

我不知道问题在哪里,请帮忙

最佳答案

设置recyclerview布局后,尝试并设置适配器。
您可以在布局之前而不是之后设置适配器。不确定是否会有所帮助。

关于android-viewpager - TabLayout,BottomSheetDialogFragment中的ViewPager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38024440/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com