SoFunction
Updated on 2025-04-09

Detailed explanation of commonly used interface parameter transfer examples in Android source code

Detailed explanation of commonly used interface parameter transfer examples in Android source code

Pass the parameters in MyCclass to MyDclass

/*Interface parameter transfer example 2
  * Send and receive
  * The principle is exactly the same as sending and receiving
  *
  */ 
public class MyCclass { 
    public void getEditext(GetMyFragmentData myFragmentData){ 
      String edStr="Human life is limited"; 
      (edStr); 
    } 
    public interface GetMyFragmentData{ 
      public void setResult(String s); 
    }; 
}
public class MyDclass {  
  public static void main(String[] args) {  
    /**
      * (getMyFragmentData);
      * is an object of an anonymous inner class. The anonymous inner class rewritten abstract methods
      * (getMyFragmentData) method is to call the method of the anonymous inner class using an anonymous inner class object (i.e., the overwritten method)
      */ 
 
     
     GetMyFragmentData getMyFragmentData=new GetMyFragmentData() {  
      @Override  
      public void setResult(String s) {  
      (s);  
          
      }  
    }; 
    MyCclass cclass = new MyCclass();  
    (getMyFragmentData);  
      
  }  
  
} 

Thank you for reading, I hope it can help you. Thank you for your support for this site!