由于某种原因,当我尝试显示 customEmpDialogFragment 时,我从 customEmpDialogFragment.show(this.getFragmentManager(); [
Posted
技术标签:
【中文标题】由于某种原因,当我尝试显示 customEmpDialogFragment 时,我从 customEmpDialogFragment.show(this.getFragmentManager(); [重复]【英文标题】:For some reason when I try to show a customEmpDialogFragment I get an error from customEmpDialogFragment.show(this.getFragmentManager(); [duplicate] 【发布时间】: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 【参考方案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();
【讨论】:
问题仍然存在。请看图片subefotos.com/ver/?d4e70f84e7d5b3175d2cc1ba14a7ae1bo.png 很抱歉,我的公司已禁止链接到您的照片。 这个问题重复了以上是关于由于某种原因,当我尝试显示 customEmpDialogFragment 时,我从 customEmpDialogFragment.show(this.getFragmentManager(); [的主要内容,如果未能解决你的问题,请参考以下文章