title: Android - How to inflate an activity layout to fragment?
body: <p>Hi I am still beginner in android programming. I have made tablayout in my program and when I click the tab I'd like the fragment to display the activity layout. </p>
  
  <p>The purpose is for the widget inside the activity such as button' and recycler view'functions can be done. </p>
  
  <p>I've tried to inflate activity layout it displayed exactly what I want however when I click a button inside, the application stop working instead of toast that what i have set. </p>
  
  <p>Is there any other method? Please help me</p>
  
  <p>Here is the logcat:</p>
  
  <pre><code>05-27 12:43:41.720 12549-12549/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                 Process: com.rumahdosen.www.rumahdosen, PID: 12549
                                                 java.lang.IllegalStateException: Could not find method clickLogin(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatButton with id 'btnLogin'
                                                     at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.resolveMethod(AppCompatViewInflater.java:325)
                                                     at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284)
                                                     at android.view.View.performClick(View.java:4463)
                                                     at android.view.View$PerformClick.run(View.java:18770)
                                                     at android.os.Handler.handleCallback(Handler.java:808)
                                                     at android.os.Handler.dispatchMessage(Handler.java:103)
                                                     at android.os.Looper.loop(Looper.java:193)
                                                     at android.app.ActivityThread.main(ActivityThread.java:5292)
                                                     at java.lang.reflect.Method.invokeNative(Native Method)
                                                     at java.lang.reflect.Method.invoke(Method.java:515)
                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
                                                     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>This is the java class for fragment</p>
  
  <pre><code>public class FragmentFriends extends Fragment {
  @Nullable
  @Override
  
  public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
      return inflater.inflate(R.layout.activity_login,container,false);
  }
  }
  </code></pre>
  
  <p>Below is the xml file of activity_login</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context="com.rumahdosen.www.rumahdosen.LoginActivity"&gt;
  
  &lt;Button
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Login"
      android:id="@+id/btnLogin"
      android:layout_below="@+id/etPswd"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="46dp"
      android:onClick="clickLogin"/&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Below is the LoginActivity.java</p>
  
  <pre><code>public class LoginActivity extends AppCompatActivity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_login);
  }
  
  public void clickLogin(View view){
             Toast.makeText(getApplicationContext(),"test",Toast.LENGTH_LONG).show();
  }
  }
  </code></pre>