I've started working on a menu for my app and I'm trying to start an activity from a fragment. My fragment code looks like this;
public class Studies extends Fragment {
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
getActivity().setTitle("Studies");
}
public void goToAttract(View v) {
Intent intent = new Intent(getActivity(), informaticainfo.class);
startActivity(intent);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.studies, container, false);
}}
I've got this working in a different project so I do not think that is the problem, my XML button to go to the next activity looks like this;
<Button
android:id="@+id/I"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginStart="0dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="40dp"
android:background="@drawable/buttonshape"
android:onClick="goToAttract" <---- is this wrong?
android:paddingLeft="130sp"
android:paddingRight="130sp"
android:text="@string/informatica"
android:textColor="#ffffff" />
I've declared the new activity in the Manifest, but the XML file keeps giving this error at the line specified above;
Cannot resolve symbol 'goToAttract' less Inspection info: Checks if the method specified in onClick XML attribute is declared in related activity.
Does the method I'm using above not work with fragments? Why can it not find the function I have working in another project?