java - Use view/layout of the base Fragment -


i have base fragment framelayout , want use layout in derived fragment , add ontouchlistener it.

basefragment.java

public class basefragment extends fragment {      protected framelayout baseframelayout;     protected view baseview;      @override     public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {          super.oncreateview(inflater, container, savedinstancestate);          baseview = inflater.inflate(r.layout.fragment_base, container, false);          baseframelayout = (framelayout) baseview.findviewbyid(r.id.framelayout);          return baseview;     } } 

fragment_base.xml

<framelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/framelayout"     android:clickable="true"      android:layout_width="wrap_content"     android:layout_height="wrap_content" /> 

derivedfragment.java

public class derivedfragment extends basefragment {      @override     public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {          super.oncreateview(inflater, container, savedinstancestate);          baseframelayout.setontouchlistener(new view.ontouchlistener() {             public boolean ontouch(view v, motionevent event) {                 //                 return true;             }         });          return baseview;     } } 

unfortunately ontouchlistener not executed when touch framelayout


edit:

finally add derivedfragment fragment in way:

overviewfragment.java

public class overviewfragment extends fragment {      @override     public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {          super.oncreateview(inflater, container, savedinstancestate);         view view = inflater.inflate(r.layout.fragment_overview, container, false);          fragment derivedfragment = new derivedfragment();         fragmenttransaction devtrans = getchildfragmentmanager().begintransaction();         devtrans.add(r.id.derivedfragmentid, derivedfragment).commit();          fragment footerfragment = new footerfragment();         fragmenttransaction stattrans = getchildfragmentmanager().begintransaction();         stattrans.add(r.id.footerfragmentid, footerfragment).commit();          return view;     } } 

fragment_overview.xml

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent">  <framelayout     android:id="@+id/derivedfragmentid"     android:layout_above="@+id/footerfragmentid"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_centerinparent="true"     android:layout_centervertical="true"     android:gravity="center"      />  <framelayout     android:id="@+id/footerfragmentid"     android:layout_alignparentbottom="true"     android:layout_width="match_parent"     android:layout_height="wrap_content"     />  </relativelayout> 

i had never used empty layouts before. tested it.

with following lines layout not visible , not clicks:

<framelayout     android:id="@+id/framelayout"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     /> 

the following lines work:

<framelayout     android:id="@+id/framelayout"     android:layout_width="match_parent"     android:layout_height="match_parent"     /> 

so either make layouts match_parent or add views inside.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -