interface - Android: Implement inner class in outer class; callback from inner class and outer class -


i have multiple fragments in 1 activity should able pass data inbetween them. have used tutorials implement callbacks. mainactivity outer class in fragment classes are. furthermore have fragmentpageradapter handles fragment transitions. thing is, eclipse wont let me implement callback interface, included in 1 of fragments, mainactivity outer class.

this structure of code:

public class mainactivity extends fragmentactivity **implements connectionfragment.datacallback**{  //compiler error here:"connectionfragment cannot resolved type"  //when leave out runtime error: "mainactivity java must  //implement datacallback"  ...      public class sectionspageradapter extends fragmentpageradapter  implements connectionfragment.datacallback{         @override         public void updatelog(view v, string line) {             datafragment datafrag = (datafragment)getsupportfragmentmanager().findfragmentbytag(datafragment.class.getname());                 if (datafrag != null){                     datafrag.updatelog(v,line);                 }         }     ...      }     public static class connectionfragment extends fragment {     ...         public interface datacallback{         public void updatelog(view v, string line);         }         datacallback mcallback;         private static datacallback dummycallback=new datacallback(){              @override              public void updatelog(view v, string line){                  }         };          @override         public void onattach(activity activity){             super.onattach(activity);             try {                 mcallback = (datacallback)activity;             } catch (classcastexception e){             throw new classcastexception(activity.tostring() + " must implement datacallback");          }     }     }     public static class datafragment extends fragment implements connectionfragment.datacallback{         public void updatelog(view v,string line){               textview logtextview=(textview)v.findviewbyid(r.id.log_view);              logtextview.append("\n"+line);     }      ...     }     public static class graphfragment extends fragment {     ...     } } 

connectionfragment should able send data datafragment.

i appreciate help!

you can't implement inner-interface or extend inner-class. move connectionfragment own file.

this because @ compile time, these inner classes dependent on parent class - , never other way around. proof, if @ compiled .class files, these inner-objects compiled mainactivity$connectionfragment.class or there-abouts. if, however, connectionfragment compiled own file (connectionfragment.cass), mainactivity.class can depend on it, , eclipse automatically handle build-order.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -