gpt4 book ai didi

android - DialogFragment 类型中的方法 show(FragmentManager, String) 不适用于参数 (FragmentTransaction, String)

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:11:19 24 4
gpt4 key购买 nike

我对 fragment 有疑问。

我面临的问题是,我有一个简单的DialogFragment

public class Fragment3 extends DialogFragment  {
private Fragment activity;
ViewGroup root;

static Fragment3 newInstance() {
Fragment3 f = new Fragment3();
return f;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
root = (ViewGroup) inflater.inflate(R.layout.fragment3_layout, container, false);
return root;
}
}

我想从另一个 fragment 创建这个 fragment

public class ListViewImageAdapter extends BaseAdapter {

private Fragment activity;
....

public ListViewImageAdapter(Fragment activity, ArrayList<Object> listImages) {
this.activity = activity;
...}

....
FragmentTransaction ft = activity.getFragmentManager().beginTransaction();
Fragment3 newFragment = Fragment3.newInstance();
newFragment.show( ft, "dialog");
....

但我收到一条消息:

The method show(FragmentManager, String) in the type DialogFragment is not applicable for the arguments (FragmentTransaction, String)

最佳答案

import android.support.v4.app.FragmentActivity;

代替:

import android.app.DialogFragment;

(或相反)

关于android - DialogFragment 类型中的方法 show(FragmentManager, String) 不适用于参数 (FragmentTransaction, String),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21626960/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com