Android Interface Interface Transfer value

Source: Internet
Author: User

Now assume that there are two classes Aclass.class and Bactivity.class, passing the value in a to the B call

1, the code in Aclass.class is as follows

public class AClass implements {  //Get interface Object     private Onaclasslistener Aclasslistener;  //Construction Method  Private AClass () {  }  //Send data public     void sends () {if (aclasslistener!= null) {  
   aclasslistener.onaclass ("Pass the value Here");               }  }      For B-bound interface public      void Setonaclass (Onaclasslistener mlistener) {          this.aclasslistener = Mlistener;}      Define interface Public      interface Onaclasslistener {          void Onaclass (String str);      }             

  

  

2, the code in Bactivity.class is as follows

public class Bactivity extends Appcompatactivity implements A.onaclasslistener {             @Override    protected void OnCreate (Bundle savedinstancestate) {        super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main); AClass a = new AClass ();        Binding interface        A.setonaclass (this); A.sends (); Call data Send}             @Override public    void Onplayercache (String str) {        log.e ("bactivity", "Incoming string:" + str);   }                

  

  

Android Interface Interface Transfer value

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.