出于某种原因,当我尝试显示customEmpDialogFragment时,我从customEmpDialogFragment.show(this.getFragmentManager();

时间:2016-08-03 08:51:17

标签: java android

你能帮我解决这个问题。我正在学习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);


            }
        }

    }

1 个答案:

答案 0 :(得分:0)

我没有看到你的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();
        }
    }