Eventbus is an open source framework that facilitates communication with various components in Android, an open source address; Https://github.com/greenrobot/EventBus. The Eventbus feature is very powerful when doing a function today. Encountered a conflict of click events and data transfer update issues.
The detail point is that there is a GridView on the header of the ListView that can be refreshed up and down. At this point, the Onitemclick event of the GridView conflicts with the Onitemclick event of the ListView.
And I'm going to do the data transfer when I implement the Griview click event.
Resolution Procedure 1:
Onitemclick Click Conflict problem, I put in the code of the Onitemclick event staring, and then in the GridView item layout by adding an ID, and then in adapter to the entire item to do an onclick () Click event, the problem is overcome.
Resolution 1: Data transfer problem, the use of Eventbus:
Register Eventbus in activity: in the OnCreate () method; Eventbus.getdefault (). Register (this);
Then in OnStop () or Ondestory (): Eventbus.getdefault (). Unregister (this);
Event handling Method Oneventmainthread:
public void Oneventmainthread (Categoryitemevent event) {
Bundle bundle = new bundle ();
Bundle.putint (...);
...//pass data, implement jump
}
What is done in adapter is the post event;
Holder.categoryRela.setOnClickListener (New Onclicklistener () {
@Override
public void OnClick (View v) {
Eventbus.getdefault (). Post (New Categoryitemevent (POS));//At the time of post, an int type of the reference POS is passed, and this parameter is Eventbus run in the activity This pos is used when Oneventmainthread (Categoryitemevent event).
}
});
Simple use of Eventbus in Android