Intent from Fragment to Activity

后端 未结 11 1519
再見小時候
再見小時候 2021-02-03 23:22

I was trying to go to another page using button, but it always fail.

Here is my First Class with its XML:

public class Fin         


        
11条回答
  •  佛祖请我去吃肉
    2021-02-03 23:56

    Try this code once-

    public class FindPeopleFragment extends Fragment {
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_home,
            container, false);
            Button button = (Button) rootView.findViewById(R.id.button1);
            button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            updateDetail();
            }
            });
            return rootView;
            }
    
    public void updateDetail() {
            Intent intent = new Intent(getActivity(), MainActivityList.class);
            startActivity(intent);
            }
    }
    

    And as suggested by Raghunandan remove below code from your fragment_home.xml-

    android:onClick="goToAttract"
    

提交回复
热议问题