[英]You must call removeView() on the child's parent first with AlertView
[英]must call removeView() on the child's parent first
我正在創建一個聊天應用程序,並且在創建組(Recycler View的列表項)並將其充氣到片段容器上時遇到問題。
實際上,兩種觀點正在被誇大。 第一個是將在片段容器中展開的根視圖,第二個是作為Dialog的另一個自定義布局放大的,要求輸入組名。
FAB被實現為單擊事件,以啟動對話框以輸入通道名稱。 第一次單擊FAB時,出現對話框,要求輸入頻道名稱以創建組。 傳遞之后,將創建一個輸入組,並創建“通道/組”(“回收者視圖”的“列表”項)並在容器上展開。 但是,當我第二次單擊FAB重復此過程以創建另一個組/通道時,應用程序崩潰了,並且在logcat上遇到了錯誤。
“指定的孩子已經有一個父母。您必須首先在該孩子的父母上調用removeView()”。
我對片段沒有太多了解,也不知道該錯誤意味着什么。 請幫助解決此錯誤。
謝謝
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_open_channel_list, container, false);
CFAlertDialogue_footerView = inflater.inflate(R.layout.cfalertdialog_footer_view_open_channel, null);
editText_ChannelName = CFAlertDialogue_footerView.findViewById(R.id.textInputEditText_channelName);
setRetainInstance(true);
mRecyclerView = rootView.findViewById(R.id.recyclerView_openChannelList);
channelListAdapter = new openChannelListAdapter(getContext());
refreshLayout = rootView.findViewById(R.id.swipe_refresh_open_channel_list);
refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
refreshLayout.setRefreshing(true);
refreshChannelList(CHANNEL_LIST_LIMIT);
}
});
actionButton = rootView.findViewById(R.id.fab_addOpenChannel);
actionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CFAlertDialog.Builder dialog = new CFAlertDialog.Builder(getContext())
.setDialogStyle(CFAlertDialog.CFAlertStyle.ALERT)
.setTitle("Create Open Channel")
.setTextGravity(Gravity.CENTER_HORIZONTAL)
.setCornerRadius(5)
.setCancelable(true)
.setFooterView(CFAlertDialogue_footerView)
.addButton("Cancel", Color.parseColor("#000000"), Color.parseColor("#f8f8ff"),
CFAlertDialog.CFAlertActionStyle.NEGATIVE, CFAlertDialog.CFAlertActionAlignment.JUSTIFIED,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.addButton("Create", Color.parseColor("#000000"), Color.parseColor("#8b3a3a"),
CFAlertDialog.CFAlertActionStyle.POSITIVE, CFAlertDialog.CFAlertActionAlignment.JUSTIFIED,
new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, int which) {
OpenChannel.createChannelWithOperatorUserIds(editText_ChannelName.getText().toString(),
null, null, null, null, new OpenChannel.OpenChannelCreateHandler() {
@Override
public void onResult(OpenChannel openChannel, SendBirdException e) {
if ( e != null){
Toast.makeText(getContext(), "Error Creating Channel: "+e.getCode()+" "
+e.getMessage(), Toast.LENGTH_SHORT).show();
return;
}
dialog.dismiss();
refreshChannelList(CHANNEL_LIST_LIMIT);
}
});
}
});
dialog.show();
}
});
setUpRecyclerViewAndAdapter();
return rootView;
}
改成
final AlertDialog.Builder b = new AlertDialog.Builder(getActivity());
b.setView(layout);
b.show();
至
final AlertDialog.Builder b = new AlertDialog.Builder(getActivity());
b.setView(layout);
final AlertDialog alertDialog = b.show();
嘗試改變這樣的事情
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.