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
Hope this code will help
public class ThisFragment extends Fragment {
public Button button = null;
Intent intent;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.yourlayout, container, false);
intent = new Intent(getActivity(), GoToThisActivity.class);
button = (Button) rootView.findViewById(R.id.theButtonid);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(intent);
}
});
return rootView;
}
You can use this code, make sure you change "ThisFragment" as your fragment name, "yourlayout" as the layout name, "GoToThisActivity" change it to which activity do you want and then "theButtonid" change it with your button id you used.