我有一个连接到片段的侧导航抽屉。在一个片段中,我有三个需要将我带到其他片段的卡片视图。我所看到的所有示例都将带有视图持有人的recyclerview实施此示例,但是我不想在此上使用recyclerview。我已经尝试了其中一个卡浏览量的以下操作,但似乎无法正常工作:
public class Dashboard extends Fragment implements View.OnClickListener {
View view;
CardView cardview1;
@Nullable
@Override
public View onCreateView (LayoutInflater inflater, @Nullable ViewGroup
container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.dashboard_fragment, container, false);
cardview1 = (CardView) view.findViewById(R.id.cardview_a);
cardview1.setOnClickListener(this);
return view;
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
getActivity().setTitle("Title");
}
@Override
public void onClick(View v) {
Fragment fragment;
switch (v.getId()) {
case R.id.cardview_a:
fragment FragmentA();
break;
}
}
}
@Override
public void onClick(View v) {
Fragment fragment;
switch (v.getId()) {
case R.id.cardview_a:
fragment = new FragmentA();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.container,fragment);
transaction.commit();
break;
}
}