I am trying to end my activity with fragment BackPressed. But the tag Key Listeneris not called at all. I searched for his problem EditText, most of the time. This is my code.
public class ProductFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.product_fragment, container,false);
view.setOnKeyListener( new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
getActivity().finish();
return true;
}
return false;
}
});
}
source
share