Using nested interfaces to communicate between two classes in java / android

can someone tell me i am right or wrong? I am really confused in solving my problem.

What I have (or what I want to do, or I think:

I have:

 Class B{

     ........
     ........
    interface I{
     ......
     ........
     }
   .......
   .......  
    } 

and:

  Class A implements B.I{
      ........
      .......
      B b= new B();
       }

Is this the right way to communicate between two classes of class B and class A? how should i do this job. I want some data from class A to be passed to class B for further operations.

how should I do the methods that I will implement in A is called from B when I need data? A simple example of an interface having the same scenario will really help me. Doea have a good explanation of how the interface works? or how to use them?

android..? , OnClick Listeners? ? :

  class A implements View.OnClickListener

onClick? , . ( , , ) , ,

, , , ? ! Thankyou

0
3

, Fragments. . Activities, Intents.

0

, , , DB. , . ActivityA DB AsyncTask, UI. AyncTask ActivityB DB

OnClickListener s, -. , , . xml

<Button
android:id="@+id/btn1"
// button attributes
android:onClick=methodName/>

java-

public void methodName(View v)
    {
     //do stuff here
    }

-

   button1.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        // do more stuff
    }
});

java- button1

, , , . , , , , , , .

0

Java. , , .

, Printable , , (, getStringRepresentation). , Printable, , .

More about interfaces here .

If you just want to transfer data from class A to class B, you do not necessarily need an interface, since you do not have several classes that can do the same thing that you might need to determine their common using the interface.

Why couldn't you just pass data from class A and an object of class B using the parameter of one of the methods of B?

eg.

// somewhere in the methods of A
B b = new B();
b.giveData(theData);
0
source

All Articles