En mi MainActivity
como puedo obtener eventos que suceden en uno de mis fragments ?
public class ManActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_formulario);
//Este boton está dentro de fragment.xml
Button tvDateB = (Button) findViewById(R.id.tvDate);
tvDateB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Boton de fragment", Toast.LENGTH_SHORT).show();
}
});
}
}
Estoy utilizando OnboardingFragment
y distintas clases de Onboarding
//Este es OnboardingFragment //Esto funciona bien, y cambio de Fragment deslizando. //Quisiera que ademas de llamar a cada layout tambien llame a la clase : "public class Fragment_1 extends Fragment {" y a cada una de las clasesde los Fragment
public class OnboardingFragment extends Fragment {
private static final String PAGE = "page";
private int backgroundColor;
private int page;
public static OnboardingFragment newInstance(int page) {
OnboardingFragment fragment = new OnboardingFragment();
Bundle b = new Bundle();
b.putInt(PAGE, page);
fragment.setArguments(b);
return fragment;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
page = getArguments().getInt(PAGE);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
int layoutResId;
switch (page) {
case 0:
layoutResId = R.layout.fragment_1;
break;
case 1:
layoutResId = R.layout.fragment_2;
break;
case 2:
layoutResId = R.layout.fragment_3;
break;
case 3:
layoutResId = R.layout.fragment_4;
break;
case 4:
layoutResId = R.layout.fragment_1;
break;
default:
layoutResId = R.layout.fragment_1;
break;
}
View view = getActivity().getLayoutInflater().inflate(layoutResId, container, false);
view.setTag(page);
return view;
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
}