如何在显示android后更改自定义对话框中的视图的可见性

时人不识凌云木,直待凌云始道高。这篇文章主要讲述如何在显示android后更改自定义对话框中的视图的可见性相关的知识,希望能为你提供帮助。
想要在显示对话框后单击某些内容来更改linearlayout的可见性。确定点击方法是真的。即使它没有点击方法也行不通。有可能吗?例:

singleA.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { linearTYT.setVisibility(View.VISIBLE)}else{linearTYT.setVisibility(View.GONE) }} });

【如何在显示android后更改自定义对话框中的视图的可见性】它在对话框代码中。
答案
使用LayoutInflator你可能想要覆盖AlertDialog's Button因为它将默认dismiss() onClick()
View view = getLayoutInflater().inflate(R.layout.your_inflated_layout, null); final LinearLayout linearLayout = view.findViewById(R.id.your_linear); // Now you can do whatever you want with LinearLayoutDialog.OnShowListener showListener = new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) {View.OnClickListener hideListener = new View.OnClickListener() { @Override public void onClick(View view) { linearLayout.setVisibility(View.INVISIBLE); } }; View.OnClickListener unHideListener = new View.OnClickListener() { @Override public void onClick(View view) { linearLayout.setVisibility(View.VISIBLE); // Hiding LinearLayout but this doesn't // dismiss the dialog if you want // call dialogInterface.dismiss(); } }; // Overriding AlertDialog's Button because we don't want it // to dismiss in every click Button hide = ((AlertDialog) dialogInterface).getButton(AlertDialog.BUTTON_POSITIVE); Button unhide = ((AlertDialog) dialogInterface).getButton(AlertDialog.BUTTON_NEGATIVE); hide.setOnClickListener(hideListener); unhide.setOnClickListener(unHideListener); } }; AlertDialog.Builder builder = new AlertDialog.Builder(this) .setView(view) .setPositiveButton("Hide", null) .setNegativeButton("Unhide", null); AlertDialog dialog = builder.create(); dialog.setOnShowListener(showListener); dialog.show();


    推荐阅读