创建聊天应用程序并在创建组时遇到问题(Recycler View的列表项)并通过片段容器对其进行充气。
实际上,有两种观点被夸大了。一个是将在片段容器中膨胀的根视图,另一个是作为Dialog的另一个自定义布局膨胀请求输入组名称。
FAB实现为单击事件以启动Dialog以输入通道名称。第一次单击FAB时,会出现一个对话框,要求输入通道名称来创建组。传递后,创建一个输入组并创建通道/组(Recycler View的列表项)并在容器上膨胀。但是当我第二次单击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;
}
答案 0 :(得分:0)
更改为
radGridView1.FilterDescriptors.Clear();
到
final AlertDialog.Builder b = new AlertDialog.Builder(getActivity());
b.setView(layout);
b.show();
尝试改变这样的事情