在android中重新加载片段?

时间:2014-11-17 06:28:55

标签: android android-fragments reload

我正在构建一个Android应用程序,在点击添加按钮时,一个viewdailog框打开,用户可以填写。

我需要的是点击该viewdailog框的ok按钮,我的片段应该重新加载,因为用户添加了vaules。

这是我在viewDialog框中使用的方法 - \

private void viewCategory() {

        AlertDialog.Builder viewDialog = new AlertDialog.Builder(getActivity());

        viewDialog.setTitle("add");

        LayoutInflater li = (LayoutInflater)     
        getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View dialogView = li.inflate(R.layout.customealertdialogbox1, null);
        viewDialog.setView(dialogView);

        viewDialog.setPositiveButton("Ok",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        name = edt1.getText().toString();
                        address = edt2.getText().toString();
                        city = edt3.getText().toString();
                        phone = edt4.getText().toString();
                        //Toast.makeText(getActivity(), name, Toast.LENGTH_SHORT).show();
                        new DownloadJSON().execute();

                    }
                });

        viewDialog.setNegativeButton("Cancel",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                    }
                });
        viewDialog.show();

        edt1 = (EditText) dialogView.findViewById(R.id.editbox1);
        edt2 = (EditText) dialogView.findViewById(R.id.editbox2);
        edt3 = (EditText) dialogView.findViewById(R.id.editbox3);
        edt4 = (EditText) dialogView.findViewById(R.id.editbox4);
 }

1 个答案:

答案 0 :(得分:1)

Fragment frg = new FirstFragment();
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.detach(frg);
ft.attach(frg);
ft.addToBackStack(FirstFragment.class.getSimpleName());
ft.commit();