'How can I start a fragment transcation in ArrayAdapter

I'm at a loss of starting a fragment transcation in ArrayAdapter which is called from a list Fragment. I have tried a few things based on this thread:

FragmentManager fm = getContext().getChildFragmentManager();
//The method getChildFragmentManager() is undefined for the type Context

FragmentManager fm = getContext().getSupportFragmentManager();
//same error above

FragmentManager fm = ((Activity) getContext()).getSupportFragmentManager();
//The method getSupportFragmentManager() is undefined for the type Activity

But none of them works, despite that getActivity() is passed when the adapter is instantiated in ListItemFragment class. Would anoyone please help me on this?

Class ListItemFragment:

import android.support.v4.app.Fragment;
import com.model.ListItem;
import com.Data;
public class ListItemFragment extends Fragment{

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {     

        super.onCreate(savedInstanceState); 

        View view = inflater.inflate(R.layout.list_container, container, false);

        ArrayList<ListItem> listItem = (ArrayList<ListItem>) Data.get();

        ListAdapter adapter = new ListAdapter(getActivity(), listItem);

        ListView listView = (ListView) view.findViewById(R.id.list_view);

        listView.setAdapter(adapter);
        return view;
    }
}

Adapter:

import com.model.ListItem;

public class ListAdapter extends ArrayAdapter<ListItem> {

    public ListAdapter(Context context, ArrayList<ListItem> listItem) {

       super(context, R.layout.list_item, listItem);

    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {

       ListItem row = getItem(position); 

       final Context context = getContext();

       LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

       view = inflater.inflate(R.layout.list_item, parent, false);

       //FragmentManager fm = ((Activity) context).getChildFragmentManager();

       //FragmentManager fm = ((Activity) context).getSupportFragmentManager();

       //FragmentManager fm = ((Activity) context).getSupportFragmentManager();

       FragmentTransaction transaction = fm.beginTransaction();

       /*......buttonFragment = call a button Fragment.......*/

       transaction.replace(R.id.placeholder, buttonFragment);

       transaction.commit();

       return view;
   }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source