Learn, Share, Build

241
September 26, 2017, at 2:46 PM

I'm customing a View and I want to listening event from there. I created a show() and hide() method then put register & unregister inside these methods. But i tried to put

public class CalculatorView extends RelativeLayout {
.......
public void show() {
    Log.i("hieu", "eventBus register");
    EventBus.getDefault().register(this);
}
public void hide() {
    EventBus.getDefault().unregister(this);
    Log.i("hieu", "eventBus unreg");
}
@Subscribe(threadMode = ThreadMode.MAIN) 
public void onEvent(EventBusMessage eventBusMessage) 
{ Log.i("hieu", ""); }

but it didn't jumped in onEvent. I'm using EventBus 3.0.0. How to archive this? Thanks.

Answer 1
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
    super(Application.class);
}
public void testRun() {
    CalculatorView view = new CalculatorView(getContext());
    view.show();
    EventBus.getDefault().post(new EventBusMessage());
    view.hide();
}
public class CalculatorView extends RelativeLayout {
    public CalculatorView(Context context) {
        super(context);
    }
    public void show() {
        Log.i("hieu", "eventBus register");
        EventBus.getDefault().register(this);
    }
    public void hide() {
        EventBus.getDefault().unregister(this);
        Log.i("hieu", "eventBus unreg");
    }
    public void onEvent(EventBusMessage eventBusMessage) {
        Log.i("hieu", "");
    }
}
class EventBusMessage {
}

}

can not this work?

it work on my test code.

Rent Charter Buses Company
READ ALSO
Learn, Share, Build

Learn, Share, Build

I have tried posting to the server using the following code:

216
Learn, Share, Build

Learn, Share, Build

There is a bunch of moving parts here so I will try to be thorough: My first Activity is a form that creates a Customer object by gathering most of the Customer object's fields and passing in 'null' for the credit card info fieldsHere is the model "Customer"...

250
Learn, Share, Build

Learn, Share, Build

Android permission when we get the write permission for something like contacts,does that mean the applcation is granted the read permission for the contacts?I remember I saw that discription in developerandroid

275
Learn, Share, Build

Learn, Share, Build

I've been recently trying to understand from an architecture point of view the relationship between the interactors and the use cases in an MVP architectureMy doubt is regarding communication in between parts and what conforms to the MVP standard

280