In my Android app, I used Activity and Adapter to view the list, I need to exchange both the adapter class and the activity through the event listener using EventBus, so I created two classes of event listener.
My process:
1) I have a button in activity, the button should inform the adapter class.
2) If you click on the text view (widgets are the type of text in the list view), you must pass the Activity class.
In the following code, it works so that the Adapter communicates with the Activity, but the Activity does not interact with the adapter class. Please help me on how to communicate for both classes?
I posted the full project code:
Action class:
public class ListMobileActivity extends Activity {....}; private ListView list; private Button btn; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); EventBus.getDefault().register(ListMobileActivity.this); ...... list.setAdapter(adapter);
Adapter Class:
public class MobileArrayAdapter extends ArrayAdapter<String> { private final Context context; private final String[] values; public MobileArrayAdapter(Context context, String[] values) { super(context, R.layout.list_mobile, values); this.context = context; this.values = values; EventBus.getDefault().register(this.context);
android greenrobot-eventbus
Mamurali
source share