I'm working on a project with Action Bar Tabs in Android. I have managed to create my fragments and achieve the desired interaction, but I have a problem. In one of those fragments I have a button, but clicking it does nothing.
This is in the code I use to call the fragment from the MainActivity:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView=null;
switch (getArguments().getInt(ARG_SECTION_NUMBER)){
case 1:
rootView = inflater.inflate(R.layout.fragment_frm_dispositivos, container, false);
//return rootView;
break;
case 2:
rootView = inflater.inflate(R.layout.fragment_frm_transaccion, container, false);
//return rootView;
break;
case 3:
rootView = inflater.inflate(R.layout.fragment_frm_cajero, container, false);
//return rootView;
break;
}
return rootView;
}
}
and this is what i do in the fragment
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view =inflater.inflate(R.layout.fragment_frm_cajero, container, false);
btnGuardar=(Button)view.findViewById(R.id.btnGuardarCajero);
btnGuardar.setOnClickListener(this);
return view;
}
@Override
public void onClick(View v) {
Toast.makeText(getContext(),"no sirve",Toast.LENGTH_SHORT).show();
}
The problem is that you are not loading the you are
fragment
simply doing ainflate
view onMainActivy
it, you only have a view loaded on the screen, not thefragment
, if what you want is to change thefragment
fromMainActivity
you must do a FragmentTransaction :MainActivity: