Problem in onClickListener with Button in Fragment to show data in Activity that contains the Fragment

0

I'm a rookie newbie on Android and I'm doing a project which contains:

ActiviyMain.class
ActivityMain.Layout
Fragment.Class
Fragment.layout

It turns out that I have a button in the Fragment.layout that is inside the ActivityMain layout, said button when pressing it must show information in the ActivityMain, but in doing so it throws me an error that I attached in the image. I remove the line from the button.onClickListener and everything runs fine.

    
asked by Rodrigo Oteiza 22.05.2017 в 07:32
source

1 answer

0

What happens is that you are defining the OnClick event in a button object that still does not have the reference to the object of the view.

Be sure to preview the button in the view:

Button button = (Button) findViewById(R.id.button);
buttonClick.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // OnClick;
        }

    });
    
answered by 22.05.2017 в 14:05