Access fragment from adapter

有些话、适合烂在心里 提交于 2019-12-01 19:05:27

You would need to pass it in your Constructor. For Example:

public class ProductOffersListAdapter extends BaseAdapter
{
 private Context context;
 private ArrayList<info.android.model.ProductsOffers> navProOffers;
 Fragment myFragment;

 public ProductOffersListAdapter(Context context, ArrayList<info.android.model.ProductsOffers> navProOffers, Fragment myFragment) 
 {
    this.context = context;
    this.myFragment = myFragment;
    this.navProOffers = navProOffers;
 }

...

What I did to resolve this is:

Intent i = new Intent(v.getContext(), MainActivity.class);                      
i.putExtra("fragment_value", "2");
v.getContext().startActivity(i);

In main class I get the parameter as value and with a switch I set fragment in main which I am interested.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!