gpt4 book ai didi

java - 如何修复 "Cannot resolve method ' 显示(android.support.v4.app.FragmentManager,java.lang.String )'"

转载 作者:行者123 更新时间:2023-12-02 03:45:35 28 4
gpt4 key购买 nike

我的代码有问题:无法解析方法“show(android.support.v4.app.FragmentManager, null)”。谁能帮我解决这个问题吗?

public void onClick(View v) {
switch (v.getId()){
case R.id.btn_profile:
break;
case R.id.btn_show_dialog:
OptionDialogFragment mOptionDialogFragment = new OptionDialogFragment();

FragmentManager mFragmentManager = getChildFragmentManager();
mOptionDialogFragment.show(mFragmentManager, OptionDialogFragment.class.getSimpleName());
break;

这些是我的进口:

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

我的选项对话框 fragment


import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.app.DialogFragment;



public class OptionDialogFragment extends Fragment implements View.OnClickListener {
Button btnChoose, btnClose;
RadioGroup rgOptions;
RadioButton rbSaf, rbMou, rbLvg, rbMoyes;
OnOptionDialogListener optionDialogListener;

public OptionDialogFragment() {
// Required empty public constructor
}

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_option_dialog, container, false);
}

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
btnChoose = view.findViewById(R.id.btn_choose);
btnChoose.setOnClickListener(this);
btnClose = view.findViewById(R.id.btn_close);
btnClose.setOnClickListener(this);
rgOptions = view.findViewById(R.id.rg_options);
rbSaf = view.findViewById(R.id.rb_saf);
rbLvg = view.findViewById(R.id.rb_lvg);
rbMou = view.findViewById(R.id.rb_mou);
rbMoyes = view.findViewById(R.id.rb_moyes);
}

@Override
public void onAttach(Context context) {
super.onAttach(context);
Fragment fragment = getParentFragment();

if (fragment instanceof DetailCategoryFragment) {
DetailCategoryFragment detailCategoryFragment = (DetailCategoryFragment) fragment;
this.optionDialogListener = detailCategoryFragment.optionDialogListener;
}
}

@Override
public void onDetach() {
super.onDetach();
this.optionDialogListener = null;
}

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_close:
getDialog().cancel();
break;

case R.id.btn_choose:
int checkedRadioButtonId = rgOptions.getCheckedRadioButtonId();
if (checkedRadioButtonId != -1) {
String coach = null;
switch (checkedRadioButtonId) {
case R.id.rb_saf:
coach = rbSaf.getText().toString().trim();
break;

case R.id.rb_mou:
coach = rbMou.getText().toString().trim();
break;

case R.id.rb_lvg:
coach = rbLvg.getText().toString().trim();
break;

case R.id.rb_moyes:
coach = rbMoyes.getText().toString().trim();
break;
}

if (optionDialogListener != null) {
optionDialogListener.onOptionChosen(coach);
}
getDialog().dismiss();
}
break;
}
}

public interface OnOptionDialogListener {
void onOptionChosen(String text);
}
}

并且在 OptionDialogFragment 中存在一个问题,即 getDialog() '无法解析方法 'getDialog ()' 以及为什么 getDialog () 出现问题,是否还缺少导入?

最佳答案

查看function public void onAttach(), optionDialogListener尚未在categoryfragment.java中详细声明

首先,您必须在detailcategoryfragment中创建optiondialoglistener

关于java - 如何修复 "Cannot resolve method ' 显示(android.support.v4.app.FragmentManager,java.lang.String )'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56809453/

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