0

以下のスクリプトを実行すると、エラーが発生しましたThe specified child already has a parent. You must call removeView() on the child's parent first.

public void EditDaytoDayTask(Bundle bundle) {
        Log.i(TAG,"Inside editdaytoday");
        //((ViewGroup)view.getParent()).removeView(view);

        final String taskName=bundle.getString("TASKDAYTODAY");
        Log.i(TAG,"TAsknamedate:"+taskName+" "+date);
        AlertDialog.Builder alertViewTaskDescription=new AlertDialog.Builder(getActivity());
        LayoutInflater inflaterViewTaskDescription=(LayoutInflater)getActivity().getSystemService(getActivity().LAYOUT_INFLATER_SERVICE);
         viewTaskWithDescription=(View)inflaterViewTaskDescription.inflate(R.layout.viewtaskwithdescriptionlayout,null,false);

        TextView textviewTask=(TextView)viewTaskWithDescription.findViewById(R.id.taskidDaytoDayView);
        TextView textviewDescription=(TextView)viewTaskWithDescription.findViewById(R.id.descriptionidDaytoDayView);
        textviewTask.setText(taskName);
        final String descriptionTask=objTaskDb.FetchDescriptionTask(date,taskName);
        textviewDescription.setText(descriptionTask);
        alertViewTaskDescription.setView(viewTaskWithDescription);
        alertViewTaskDescription.setPositiveButton("EDIT",new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                //((ViewGroup)view.getParent()).removeView(view);

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

                LayoutInflater inflaterEditTaskDescription=(LayoutInflater)getActivity().getSystemService(getActivity().LAYOUT_INFLATER_SERVICE);

                View viewEditTaskDescription=(View)inflaterEditTaskDescription.inflate(R.layout.edittaskwithdescriptionlayout,null,false);
                //((ViewGroup)viewEditTaskDescription.getParent()).removeAllViews();
                EditText edittextTask=(EditText)viewEditTaskDescription.findViewById(R.id.taskidDaytoDayEdit);
                EditText edittextDescription=(EditText)viewEditTaskDescription.findViewById(R.id.descriptionidDaytoDayEdit);
                edittextTask.setText(taskName);
                edittextDescription.setText(descriptionTask);
                alertEditTaskDescription.setView(edittextDescription);
                alertEditTaskDescription.setPositiveButton("OK", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });

        alertViewTaskDescription.show();

    }
}

このエラーを解決するにはどうすればよいですか? どんな助けでも感謝します、ありがとう。

4

2 に答える 2

1

はい、このエラーを見つけて解決します。これは私の単純な間違いです。setview でビューの代わりに編集テキストを追加します。

alertEditTaskDescription.setView(viewEditTaskDescription);

instead of this

 alertEditTaskDescription.setView(edittextDescription);
于 2013-06-28T07:35:14.817 に答える
0

私にとってはうまくいきます..

public void EditDaytoDayTask() {
        // Log.i(TAG,"Inside editdaytoday");
        //((ViewGroup)view.getParent()).removeView(view);

        //final String taskName=bundle.getString("TASKDAYTODAY");
        //Log.i(TAG,"TAsknamedate:"+taskName+" "+date);
        final AlertDialog.Builder alertViewTaskDescription=new AlertDialog.Builder(hostActReference);
        LayoutInflater inflaterViewTaskDescription=(LayoutInflater)hostActReference.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View viewTaskWithDescription = (View)inflaterViewTaskDescription.inflate(R.layout.pdf_save_dialog,null,false);

        //TextView textviewTask=(TextView)viewTaskWithDescription.findViewById(R.id.taskidDaytoDayView);
        //TextView textviewDescription=(TextView)viewTaskWithDescription.findViewById(R.id.descriptionidDaytoDayView);
        //textviewTask.setText(taskName);
        //final String descriptionTask=objTaskDb.FetchDescriptionTask(date,taskName);
        // textviewDescription.setText(descriptionTask);
        alertViewTaskDescription.setView(viewTaskWithDescription);
        alertViewTaskDescription.setPositiveButton("EDIT",new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                //((ViewGroup)view.getParent()).removeView(view);

                AlertDialog.Builder alertEditTaskDescription=new AlertDialog.Builder(hostActReference);

                LayoutInflater inflaterEditTaskDescription=(LayoutInflater)hostActReference.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

                View edittextDescription=(View)inflaterEditTaskDescription.inflate(R.layout.save_dialog,null,false);
                //((ViewGroup)viewEditTaskDescription.getParent()).removeAllViews();
                //EditText edittextTask=(EditText)viewEditTaskDescription.findViewById(R.id.taskidDaytoDayEdit);
                //  EditText edittextDescription=(EditText)viewEditTaskDescription.findViewById(R.id.descriptionidDaytoDayEdit);
                //edittextTask.setText(taskName);
                //edittextDescription.setText(descriptionTask);
                alertEditTaskDescription.setView(edittextDescription);
                alertEditTaskDescription.setPositiveButton("OK", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {


                    }
                });

                alertEditTaskDescription.setNegativeButton("Cancel", null);

                alertEditTaskDescription.create().show();

            }
        });

        alertViewTaskDescription.setNegativeButton("Cancel", null);


        alertViewTaskDescription.create().show();


    }
于 2013-06-27T11:55:36.850 に答える