user1518451
user1518451

Reputation: 1845

Call element from fragment in Adapter

My situation: I have Activity with Fragments. In Activity I have GridView genereted by adapter. When I click on the element in GridView I call onClickListener in Adapter class. How can I call element from another fragment in this listener ?

Upvotes: 1

Views: 587

Answers (1)

bakriOnFire
bakriOnFire

Reputation: 2681

Android has provided a nice documentation on Communicating with Fragments.

Check this out.

EDIT

when adding, add the fragment with tag..

MyFragment myFragment = new MyFragment();
fragmentTransaction.add(R.id.fragment_container, myFragment, "myfrag");
fragmentTransaction.commit();

and retrive it like this

MyFragment myFragment = (MyFragment) getFragmentManager().findFragmentByTag("myfrag");

Upvotes: 1

Related Questions