我一直想解决这个问题,我想将数据从Fragment传递到其他Fragment,model.getPid建议我是静态的!,然后运行应用程序并单击图像,然后该应用程序崩溃了!预先感谢!
holder.imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ProductsDetailsFragment fragment = new ProductsDetailsFragment();
Bundle b1 = new Bundle();
b1.putString("pid", Products.getPid());
fragment.setArguments(b1);
FragmentManager fragmentManager =
getActivity().getSupportFragmentManager();
FragmentTransaction ft = fragmentManager.beginTransaction();
ft.replace(R.id.nav_host_fragment, fragment)
.addToBackStack(null)
.commit();
这是来自第二个片段
Bundle bundle = this.getArguments();
if (bundle != null) {
productID= bundle.getString("pid");
getProductDetails(productID);
}
在FirebaseAdapter中,当我通过ProductTD时,它返回null
private void getProductDetails(String productID) {
DatabaseReference productRef = FirebaseDatabase.getInstance().getReference().child("Products");
productRef.child(productID).addValueEventListener(new ValueEventListener() {
@Override
这是来自Logcat的>
java.lang.NullPointerException: Can't pass null for argument 'pathString' in child()
我一直想解决这个问题,我想将数据从Fragment传递到其他Fragment,model.getPid建议我是静态的,并且在运行应用程序后... ...>
这是您的错误Intent intent = new Intent(getActivity(), ProductsDetailsFragment.class);
intent.putExtra("pid", model.getPid());
startActivity(intent)
删除此内容,可以将意图用于片段