title: Button doesn't work when adding to fragment
body: <p>I have a button in an fragment that when I clicked on it nothing happens at all</p>
  
  <p>this is the java code of the fragment:</p>
  
  <pre><code>public class HomeFragment extends Fragment {
      // TODO: Rename parameter arguments, choose names that match
      // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
      private static final String ARG_PARAM1 = "param1";
      private static final String ARG_PARAM2 = "param2";
  
      // TODO: Rename and change types of parameters
      private String mParam1;
      private String mParam2;
  
      private OnFragmentInteractionListener mListener;
  
      EditText etAddPost;
      Button addPostImage;
  
      FirebaseDatabase database = FirebaseDatabase.getInstance();
      DatabaseReference myRef;
  
      public HomeFragment() {
          // Required empty public constructor
      }
  
      /**
       * Use this factory method to create a new instance of
       * this fragment using the provided parameters.
       *
       * @param param1 Parameter 1.
       * @param param2 Parameter 2.
       * @return A new instance of fragment HomeFragment.
       */
      // TODO: Rename and change types and number of parameters
      public static HomeFragment newInstance(String param1, String param2) {
          HomeFragment fragment = new HomeFragment();
          Bundle args = new Bundle();
          args.putString(ARG_PARAM1, param1);
          args.putString(ARG_PARAM2, param2);
          fragment.setArguments(args);
          return fragment;
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          if (getArguments() != null) {
              mParam1 = getArguments().getString(ARG_PARAM1);
              mParam2 = getArguments().getString(ARG_PARAM2);
          }
  
          database = FirebaseDatabase.getInstance();
          myRef = database.getReference("posts");;
  
      }
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          View rootView = inflater.inflate(R.layout.fragment_home, container, false);
          etAddPost =rootView.findViewById(R.id.etAddPost);
          addPostImage = rootView.findViewById(R.id.addPostBtn);
          addPostImage.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  Toast.makeText(getActivity(), "Clicked", Toast.LENGTH_SHORT).show();
                  String postText = etAddPost.getText().toString();
                  if(TextUtils.isEmpty(postText)){
                      etAddPost.setError("لا يمكنك ترك هذا الحقل فارغا");
                  }
                  else {
                      Map&lt;String, String&gt; map = new HashMap&lt;&gt;();
                      map.put("postContent", postText);
                      myRef.push().setValue(map);
                      etAddPost.setText("");
                  }
              }
          });        return rootView;
      }
  
      // TODO: Rename method, update argument and hook method into UI event
      public void onButtonPressed(Uri uri) {
          if (mListener != null) {
              mListener.onFragmentInteraction(uri);
          }
      }
  
      @Override
      public void onAttach(Context context) {
          super.onAttach(context);
          if (context instanceof OnFragmentInteractionListener) {
              mListener = (OnFragmentInteractionListener) context;
          } else {
              throw new RuntimeException(context.toString()
                      + " must implement OnFragmentInteractionListener");
          }
      }
  
      @Override
      public void onDetach() {
          super.onDetach();
          mListener = null;
      }
  "http://developer.android.com/training/basics/fragments/communicating.html"
       * &gt;Communicating with Other Fragments&lt;/a&gt; for more information.
       */
      public interface OnFragmentInteractionListener {
          // TODO: Update argument type and name
          void onFragmentInteraction(Uri uri);
      }
  }
  </code></pre>
  
  <p>and this is my XML code : </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@color/color3"
      tools:context="com.mk.playAndLearn.fragment.HomeFragment"&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:background="@color/white"
          android:orientation="horizontal"&gt;
  
          &lt;Button
              android:id="@+id/addPostBtn"
              android:layout_width="0dp"
              android:layout_height="30dp"
              android:layout_weight="1"
              android:layout_margin="5dp"
              android:background="@drawable/send"
              android:layout_marginRight="5dp"/&gt;
  
          &lt;EditText
              android:layout_margin="5dp"
              android:id="@+id/etAddPost"
              android:layout_width="0dp"
              android:gravity="right"
              android:layout_height="wrap_content"
              android:layout_weight="7"
              android:hint="ماذا يخطر في بالك؟"
              android:paddingRight="10dp"/&gt;
  
  
      &lt;/LinearLayout&gt;
      &lt;android.support.v7.widget.RecyclerView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"/&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>I have tried a lot to solve this problem but I couldn't but I am feeling that solving the problem is easy so I hope that any one helps me to solve this problem I tried to change the button type and use ImageButton instead but that doesn't solve the problem  </p>