-2

I have a button in my screen, I need to pass boolean value while click on the button.

Here while click on the button it starts a fragment and opens an another screen there I need to show only a button.

In the same way, the same button needs to show all the screen view If I navigate from an another fragment.

Can I able to send a boolean value along this and how it will be retrieved in another fragment?

   case R.id.tv_send:
        fragment = UserFragment.newInstance(this, mModel);
        break;
sejn
  • 2,040
  • 6
  • 28
  • 82

1 Answers1

0

user Argument to pass value fragment to fragment like this

put your Boolean value

fragment = UserFragment.newInstance(this, mModel);
Bundle b = new Bundle();
b.putBoolean("onPress",true);
fragment.setArguments(b);

get your value for another fragment

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

            boolean getValue = getArguments().getBoolean("onPress");
            
        }
milan pithadia
  • 840
  • 11
  • 16
  • In the same way after geting the data in a fragment, how can I send this value to an adapter.(boolean getValue = getArguments().getBoolean("onPress"); to an adapter – sejn Mar 30 '21 at 15:41