【问题标题】:For some reason when I try to show a customEmpDialogFragment I get an error from customEmpDialogFragment.show(this.getFragmentManager(); [duplicate]由于某种原因,当我尝试显示 customEmpDialogFragment 时,我从 customEmpDialogFragment.show(this.getFragmentManager(); [重复]
【发布时间】:2016-12-08 21:25:54
【问题描述】:

你能帮我解决这个问题吗?我正在学习 Android,所以不知道会发生什么.. image link error

最后一行代码的问题:customEmpDialogFragment.show(this.getFragmentManager(), CustomEmpDialogFragment.ARG_ITEM_ID);

希望你能帮助我。

public class EmpListFragment extends Fragment implements AdapterView.OnItemClickListener,
    AdapterView.OnItemLongClickListener {

        public static final String ARG_ITEM_ID = "employee_list";

        Activity activity;
        ListView employeeListView;
        ArrayList < Employee > employees;

        EmpListAdapter employeeListAdapter;
        EmployeeDAO employeeDAO;

        private GetEmpTask task;

        @
        Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            activity = getActivity();
            employeeDAO = new EmployeeDAO(activity);
        }

        @
        Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
            View view = inflater.inflate(R.layout.activity_emp_list_fragment, container,
                false);
            findViewsById(view);

            task = new GetEmpTask(activity);
            task.execute((Void) null);

            employeeListView.setOnItemClickListener(this);
            employeeListView.setOnItemLongClickListener(this);
            // Employee e = employeeDAO.getEmployee(1);
            // Log.d("employee e", e.toString());
            return view;
        }

        private void findViewsById(View view) {
            employeeListView = (ListView) view.findViewById(R.id.list_emp);
        }

        @
        Override
        public void onResume() {
            getActivity().setTitle(R.string.app_name);
            getActivity().getActionBar().setTitle(R.string.app_name);
            super.onResume();
        }

        @
        Override
        public void onItemClick(AdapterView <? > list, View arg1, int position,
            long arg3) {
            Employee employee = (Employee) list.getItemAtPosition(position);

            if (employee != null) {
                Bundle arguments = new Bundle();
                arguments.putParcelable("selectedEmployee", employee);
                CustomEmpDialogFragment customEmpDialogFragment = new CustomEmpDialogFragment();
                customEmpDialogFragment.setArguments(arguments);
                customEmpDialogFragment.show(this.getFragmentManager(), CustomEmpDialogFragment.ARG_ITEM_ID);


            }
        }

    }

【问题讨论】:

  • 到目前为止你的问题是什么?
  • 这行代码是红色的:customEmpDialogFragment.show(this.getFragmentManager(), CustomEmpDialogFragment.ARG_ITEM_ID);
  • 问题仍然存在。请看图片 subefotos.com/ver/?d4e70f84e7d5b3175d2cc1ba14a7ae1bo.png

标签: java android


【解决方案1】:

我没有看到您的 logcat,我认为您在显示片段时遇到了问题。试试这个。

Bundle arguments = new Bundle();
            arguments.putParcelable("selectedEmployee", employee);
            CustomEmpDialogFragment customEmpDialogFragment = new CustomEmpDialogFragment();
            customEmpDialogFragment.setArguments(arguments);
addFragment(R.id.fl_home_container, fragment, "Fragment1");  



public void addFragment(int container, Fragment fragment, String tag) {
        FragmentActivity activity = getActivity();
        if (activity != null && !activity.isFinishing()) {
            getActivity().getSupportFragmentManager().beginTransaction().add(container, fragment, tag).addToBackStack(tag).commit();
        }
    }

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2017-08-17
  • 2021-02-08
  • 2022-11-12
  • 1970-01-01
  • 1970-01-01
  • 2014-10-22
  • 2023-03-15
  • 2021-04-05
相关资源
最近更新 更多