I need to call an Activity through a Fragment, I looked for some answers but they didn’t work

Asked

Viewed 30 times

-2

JAVA

public class Contactofragment extends Fragment {

Button btnMaps;
TextView txtMaps;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    return inflater.inflate(R.layout.fragment_contato, container, false);}

    public void onViewCreated (Bundle savedInstanceState){
       txtMaps= (TextView) txtMaps.findViewById(R.id.txtMaps);

       txtMaps.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               Intent intent = new Intent(getContext(), MapsActivity.class);
             startActivity(intent);

           }
       });
    }

}`

1 answer

0

Try to change the section

Intent intent = new Intent(getContext(), MapsActivity.class);

for

Intent intent = new Intent(getActivity(), MapsActivity.class);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.