When you click on the button that is on the fragment, the click is not processed.

public class LoginFragment extends android.app.Fragment implements View.OnClickListener { public LoginFragment() { // Required empty public constructor } Button button; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_login, null); button = (Button) v.findViewById(R.id.btnLogin); button.setOnClickListener(this); // присвоСниС ΠΊΠ½ΠΎΠΏΠΊΠΈ листСнСру return inflater.inflate(R.layout.fragment_login, container, false); } @Override public void onClick(View v) { Toast.makeText(getActivity(),"2134",Toast.LENGTH_LONG).show(); } } 

The issue resolved the problem was in this line

 View v = inflater.inflate(R.layout.fragment_login, container, false); 

    1 answer 1

    You create a layout from xml, subscribe to a button in it, and then create a new layout and display it. But the button with the listener in the old remained! Return the first layout and you will be happy:

     @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_login, container, false); button = (Button) v.findViewById(R.id.btnLogin); button.setOnClickListener(this); // присвоСниС ΠΊΠ½ΠΎΠΏΠΊΠΈ листСнСру return v; } 
    • Plus most likely the wrong fragment is used. android.app.Fragment instead of android.support.v4.app.Fragment - Android Android
    • @AndroidAndroid if the fragment is shown, then he is the one. More precisely, even if compiled. - xkor
    • @AndroidAndroid I can not use android.support.v4.app.Fragment? since, when declaring it in FragmentTransaction, it emphasizes to me and produces: "Wrong 2nd argument type. Found: 'com.example.miza.prototype2.fragments.LoginFragment', required: 'android.app.Fragment'", and when returning v my whole fragment is not correctly shown ... - Dmitry_Che
    • uh, so you return it anyway ... - xkor
    • @xkor well, when I return v, one editText disappears and everything moves into a corner. - Dmitry_Che