无法解析适配器中的 getSupportFragmentManager()

a.s*_*rto 0 android adapter fragment android-dialogfragment

我有这个适配器,但有这样的问题:

无法解析方法“getSupportFragmentManager()”

Fragment 是一个 DialogFragment 并且该类扩展了 AppCompatDialogFragment 我可以以其他方式启动这个 Fragment 吗?或者有解决办法吗?

public class PostAdapterProfile extends ArrayAdapter<Post> {
private int resource;
private LayoutInflater inflater;
private FirebaseDatabase mFirebaseDatabase;
private DatabaseReference mDatabaseReferences;
SharedPreferences prefs;
private String uuid;
private boolean verifyStar;
private User currentUserPost;

public PostAdapterProfile(@NonNull Context context, int resourceId, ArrayList<Post> objects) {
    super(context, resourceId, objects);
    resource = resourceId;
    inflater = LayoutInflater.from(context);
}

public View getView(int position, View v, ViewGroup parent) {
    if (v == null) {
        Log.d("DEBUG", "Inflating view");
        v = inflater.inflate(R.layout.list_element, null);
    }

    mFirebaseDatabase = FirebaseDatabase.getInstance();
    mDatabaseReferences = mFirebaseDatabase.getReference();

    prefs = PreferenceManager.getDefaultSharedPreferences(v.getContext());
    uuid = prefs.getString("RECORDMAN1", "");
    CurrentUser c = (CurrentUser)getContext().getApplicationContext();
    currentUserPost = c.getUserPost();

    final Post p = getItem(position);

    SharedPreferences.Editor editor = prefs.edit();
    editor.putString("postId", p.getId());

    Log.d("DEBUG", "contact c=" + p);
    final Button nameButton;
    TextView testoView, dataView;
    ImageView profile_pic;
    final ImageView imagePost;
    final Button likeButtonGrey, likeButtonOk, numberLike, commentaButton;// redHeart, blackHeart;
    ImageButton xButton;

    xButton = (ImageButton) v.findViewById(R.id.deleteButton);
    xButton.setVisibility(View.VISIBLE);
    xButton.setBackgroundResource(R.mipmap.x);
    xButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            android.support.v4.app.FragmentManager manager = getSupportFragmentManager();
            FragmentEliminaPost fragmentEliminaPost = new FragmentEliminaPost();
            fragmentEliminaPost.show(manager, "ahahahaha");
        }
    });
Run Code Online (Sandbox Code Playgroud)

ADM*_*ADM 6

getSupportFragmentManager()AppCompatActivitynot 的方法ArrayAdapter
如果你想使用它,你可以通过活动上下文使用它。对于你的情况。

  ((AppCompatActivity)context).getSupportFragmentManager();
Run Code Online (Sandbox Code Playgroud)