android - how can I merg 2 xml layout with their java class? -


hi there have 2 xml layout , 2 java class. want merg them.

in main.activity.java call them method:

switch (position % 4) {                     case 0:                         return webviewgoogle.newinstance();                     case 1:                         return scrollfragment.newinstance();                 } 

scrollfragment.java:

public class scrollfragment extends fragment {      private observablescrollview mscrollview;      public static scrollfragment newinstance() {         return new scrollfragment();     }      @override     public view oncreateview(layoutinflater inflater, @nullable viewgroup container, @nullable bundle savedinstancestate) {         return inflater.inflate(r.layout.fragment_scroll, container, false);     }      @override     public void onviewcreated(view view, @nullable bundle savedinstancestate) {         super.onviewcreated(view, savedinstancestate);         mscrollview = (observablescrollview) view.findviewbyid(r.id.scrollview);         materialviewpagerhelper.registerscrollview(getactivity(), mscrollview, null);     } } 

also webviewgoogle.java

public class webviewgoogle extends fragment {      private observablewebview mwebview;      public static webviewgoogle newinstance() {         return new webviewgoogle();     }      @override     public view oncreateview(layoutinflater inflater, @nullable viewgroup container, @nullable bundle savedinstancestate) {         return inflater.inflate(r.layout.webview_layout, container, false);     }      @override     public void onviewcreated(view view, @nullable bundle savedinstancestate) {         super.onviewcreated(view, savedinstancestate);         mwebview = (observablewebview) view.findviewbyid(r.id.webviewpars);          materialviewpagerhelper.preloadinjectheader(mwebview);          mwebview.setwebviewclient(new webviewclient() {             @override             public void onpagefinished(webview view, string url) {                 materialviewpagerhelper.injectheader(mwebview, true);             }             @override             public boolean shouldoverrideurlloading(webview view, string url) {                 view.loadurl(url);                 return true;             }         });         mwebview.loadurl("http://www.google.com");             materialviewpagerhelper.registerwebview(getactivity(), mwebview, null);     } } 

now have 2 xml file content:

fragment_scroll.xml:

<com.github.ksoichiro.android.observablescrollview.observablescrollview     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     android:id="@+id/scrollview"     android:layout_width="match_parent"     android:layout_height="match_parent">      <linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:orientation="vertical">          <include layout="@layout/material_view_pager_placeholder"/>          <android.support.v7.widget.cardview             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_marginbottom="@dimen/cardmarginvertical"             android:layout_marginleft="@dimen/cardmarginhorizontal"             android:layout_marginright="@dimen/cardmarginhorizontal"             android:layout_margintop="@dimen/cardmarginvertical"             android:background="@android:color/white"             app:cardelevation="4dp">              <linearlayout                 android:layout_width="match_parent"                 android:layout_height="1000dp"                 android:orientation="vertical">              </linearlayout>          </android.support.v7.widget.cardview>     </linearlayout>  </com.github.ksoichiro.android.observablescrollview.observablescrollview> 

and xml webview_layout.xml:

<framelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:paddingleft="5dp"     android:paddingright="5dp"     >      <com.github.ksoichiro.android.observablescrollview.observablewebview xmlns:android="http://schemas.android.com/apk/res/android"         android:id="@+id/webviewpars"         android:background="@android:color/transparent"         android:layout_width="match_parent"         android:layout_height="match_parent" /> </framelayout> 

these 2 layout , java class work correctly now.

but want merge them. why? because want put webview in cardview

so merhe 2 xml layouts in these way: (newlayout.xml)

<com.github.ksoichiro.android.observablescrollview.observablescrollview     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     android:id="@+id/scrollview"     android:layout_width="match_parent"     android:layout_height="match_parent">      <linearlayout         android:layout_width="match_parent"         android:layout_height="match_parent"         android:orientation="vertical">          <include layout="@layout/material_view_pager_placeholder"/>          <android.support.v7.widget.cardview             android:layout_width="match_parent"             android:layout_height="match_parent"             android:layout_marginbottom="@dimen/cardmarginvertical"             android:layout_marginleft="@dimen/cardmarginhorizontal"             android:layout_marginright="@dimen/cardmarginhorizontal"             android:layout_margintop="@dimen/cardmarginvertical"             android:background="@android:color/white"             app:cardelevation="4dp">              <linearlayout                 android:layout_width="match_parent"                 android:layout_height="1000dp"                 android:orientation="vertical">                 <framelayout xmlns:android="http://schemas.android.com/apk/res/android"                     android:layout_width="match_parent"                     android:layout_height="match_parent"                     android:paddingleft="5dp"                     android:paddingright="5dp"                     >                      <com.github.ksoichiro.android.observablescrollview.observablewebview xmlns:android="http://schemas.android.com/apk/res/android"                         android:id="@+id/webviewpars"                         android:background="@android:color/transparent"                         android:layout_width="match_parent"                         android:layout_height="match_parent" />                 </framelayout>             </linearlayout>          </android.support.v7.widget.cardview>     </linearlayout>  </com.github.ksoichiro.android.observablescrollview.observablescrollview> 

i think true how can java class?

step 1:

i create new java claaa:

newclass.java

step 2

in main_activity call it:

case 3: return newclass.newinstance(); 

now have 2 id in newlayout: scrollview , webviewpars...now how can merge 2 java class ...?


Comments