2013-06-27 75 views
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(); 

    } 
} 

如何解決這個問題?任何幫助將不勝感激,謝謝。

+0

你得到這個錯誤是因爲你正在向另一個視圖添加一些視圖。但是你添加的視圖已經是某個視圖的孩子了。所以基本上你必須調用父視圖上的removeview。在哪一行你得到這個錯誤? –

+0

我有一個創建視圖和以上兩個視圖在內部類中的回調目的。 – Satheesh

+0

我的第一個警報對話框有兩個文本視圖,然後我按下警報框中的編輯按鈕它顯示另一個警報框有兩個edittext而不是textview ....謝謝 – Satheesh

回答

1

海我發現這個錯誤並解決it.This是我簡單的錯誤在setview.I更改添加編輯文本,而不是觀點

alertEditTaskDescription.setView(viewEditTaskDescription); 

instead of this 

alertEditTaskDescription.setView(edittextDescription); 
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(); 


    } 
+0

不工作我得到了一個同樣的錯誤... – Satheesh

+0

如果可能的話,分享您的完整源代碼 – MohsinSyd

+0

等待我將發送 – Satheesh