How to use FindviewById and Onclick on a fragment?

0

I added two tabs in the main activity layout, and created two java class, one for each tab. So I took the activity xml buttons from main activity and put it in the fragment layout, but I will use the find view by id in the java class of the fragment and it did not work.

public class FragmentA extends Fragment {

    public ImageButton trans ;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate( R.layout.fragment_a, container, false );

    trans = (ImageButton)findViewByID(R.id.imagem)

    }
}
    
asked by anonymous 09.07.2017 / 20:48

1 answer

2

This class oncreateview has to return a view then to use findviewbyid you have to use the view like this:

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

    View v = inflater.inflate(R.layout.fragmentlistavideos, container, false);
    mRecyclerView = (RecyclerView) v.findViewById(R.id.mRecicleview);
    return v;
}
    
09.07.2017 / 20:51