Android 如何使另一个类中的类的图像按钮可见?
我有两门课:Android 如何使另一个类中的类的图像按钮可见?,android,class,kotlin,Android,Class,Kotlin,我有两门课: RateBottomSheet(它有自己的布局) CustomRateBar(是一个自定义项) 我想从CustomRateBar类管理RateBottomSheetLayout某些项目的可见性。 我试着在2中引用类1。但结果并非如此。有人有主意吗?我在一个倾听者中思考。但是参数应该是什么呢?风景?有人举个例子吗 等级费率底页: ´class RateBottomSheet : BottomSheetDialogFragment(){ fun events() { imgEm
´class RateBottomSheet : BottomSheetDialogFragment(){
fun events() {
imgEmoji.visible()
feeling.visible()
title.gone()
subtitle.gone()
txtOpinion.visible()
btnSubmit.visible()
}
private var fragmentView: View? = null
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
fragmentView = inflater.inflate(R.layout.score_bottom_sheet, container, false)
doBounceAnimation(this.fragmentView)
return fragmentView
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(STYLE_NORMAL, R.style.SheetDialog)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
customRB.init(5, context!!)
}
´class CustomRatingBar : LinearLayout {
var vChildrens: MutableList<View>? = null
var mContext = context
var size: Int? = null
constructor(
context: Context?,
onSelectedStar: IOnSelectedStar
) : super(context) {
this.onSelectedStar = onSelectedStar
}
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
fun init(item: Int, context: Context) {
this.size = item
this.mContext = context
populate()
}
fun populate() {
vChildrens = ArrayList()
val lp = LayoutParams(
(FrameLayout.LayoutParams.MATCH_PARENT),
(FrameLayout.LayoutParams.WRAP_CONTENT)
)
var vChildren: View
for (item in 1..size!!) {
vChildren = buildStars(item)
vChildren.layoutParams = lp
this.addView(vChildren)
vChildrens!!.add(vChildren)
}
this.requestLayout()
}
fun buildStars(num: Int): View {
val item = LayoutInflater.from(context).inflate(R.layout.item_ratingbar, null)
item.tag = num
var viewHolder = ViewHolder(view = item)
val unSelectedColor = PorterDuffColorFilter(
ContextCompat.getColor(
context,
R.color.btn_specialities_background
), PorterDuff.Mode.SRC_IN
)
viewHolder.starItem.colorFilter = unSelectedColor
viewHolder.starItem.setOnClickListener {
LogUtils().v("selectOn old", " ${selectOn}")
for (u in 0 until vChildrens!!.size) {
val vChildrenn: View = vChildrens!![u]
viewHolder = ViewHolder(view = vChildrenn)
LogUtils().v("item", " ${item.tag.toString().toInt()}")
if (item.tag.toString().toInt() < selectOn || item.tag.toString().toInt() > selectOn && first ) {
**here I want to call the class event of the another class**
}
if (vChildrenn.tag.toString().toInt() <= item.tag.toString().toInt()) {
val selectedColor = PorterDuffColorFilter(
ContextCompat.getColor(
context,
R.color.star_color
), PorterDuff.Mode.SRC_IN
)
viewHolder.starItem.colorFilter = selectedColor
} else {
viewHolder.starItem.colorFilter = unSelectedColor
}
}
return item
}
inner class ViewHolder(view: View) {
var starItem = view.findViewById<View>(R.id.starItem) as ImageButton
}
}`
类定制栏:
´class RateBottomSheet : BottomSheetDialogFragment(){
fun events() {
imgEmoji.visible()
feeling.visible()
title.gone()
subtitle.gone()
txtOpinion.visible()
btnSubmit.visible()
}
private var fragmentView: View? = null
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
fragmentView = inflater.inflate(R.layout.score_bottom_sheet, container, false)
doBounceAnimation(this.fragmentView)
return fragmentView
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(STYLE_NORMAL, R.style.SheetDialog)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
customRB.init(5, context!!)
}
´class CustomRatingBar : LinearLayout {
var vChildrens: MutableList<View>? = null
var mContext = context
var size: Int? = null
constructor(
context: Context?,
onSelectedStar: IOnSelectedStar
) : super(context) {
this.onSelectedStar = onSelectedStar
}
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
fun init(item: Int, context: Context) {
this.size = item
this.mContext = context
populate()
}
fun populate() {
vChildrens = ArrayList()
val lp = LayoutParams(
(FrameLayout.LayoutParams.MATCH_PARENT),
(FrameLayout.LayoutParams.WRAP_CONTENT)
)
var vChildren: View
for (item in 1..size!!) {
vChildren = buildStars(item)
vChildren.layoutParams = lp
this.addView(vChildren)
vChildrens!!.add(vChildren)
}
this.requestLayout()
}
fun buildStars(num: Int): View {
val item = LayoutInflater.from(context).inflate(R.layout.item_ratingbar, null)
item.tag = num
var viewHolder = ViewHolder(view = item)
val unSelectedColor = PorterDuffColorFilter(
ContextCompat.getColor(
context,
R.color.btn_specialities_background
), PorterDuff.Mode.SRC_IN
)
viewHolder.starItem.colorFilter = unSelectedColor
viewHolder.starItem.setOnClickListener {
LogUtils().v("selectOn old", " ${selectOn}")
for (u in 0 until vChildrens!!.size) {
val vChildrenn: View = vChildrens!![u]
viewHolder = ViewHolder(view = vChildrenn)
LogUtils().v("item", " ${item.tag.toString().toInt()}")
if (item.tag.toString().toInt() < selectOn || item.tag.toString().toInt() > selectOn && first ) {
**here I want to call the class event of the another class**
}
if (vChildrenn.tag.toString().toInt() <= item.tag.toString().toInt()) {
val selectedColor = PorterDuffColorFilter(
ContextCompat.getColor(
context,
R.color.star_color
), PorterDuff.Mode.SRC_IN
)
viewHolder.starItem.colorFilter = selectedColor
} else {
viewHolder.starItem.colorFilter = unSelectedColor
}
}
return item
}
inner class ViewHolder(view: View) {
var starItem = view.findViewById<View>(R.id.starItem) as ImageButton
}
`class CustomRatingBar:LinearLayout{
变量vChildrens:可变列表?=null
var mContext=上下文
变量大小:Int?=null
建造师(
上下文:上下文?,
onSelectedStar:onSelectedStar
):super(上下文){
this.onSelectedStar=onSelectedStar
}
构造函数(context:context?,attrs:AttributeSet?):super(context,attrs)
趣味初始化(项:Int,上下文:context){
this.size=项目
this.mContext=上下文
填充()
}
乐趣(){
vChildrens=ArrayList()
val lp=布局参数(
(FrameLayout.LayoutParams.MATCH_PARENT),
(FrameLayout.LayoutParams.WRAP_内容)
)
var vChildren:视图
用于(1.尺寸中的项目!!){
vChildren=buildStars(项目)
vChildren.layoutParams=lp
this.addView(vChildren)
vChildrens!!.add(vChildren)
}
this.requestLayout()
}
趣味buildStars(num:Int):查看{
val item=LayoutFlater.from(上下文)。充气(R.layout.item_ratingbar,空)
item.tag=num
var viewHolder=viewHolder(视图=项目)
val unSelectedColor=PorterDuffColorFilter(
ContextCompat.getColor(
上下文
R.color.btn_特殊性_背景
),PorterDuff.Mode.SRC_IN
)
viewHolder.starItem.colorFilter=未选择的颜色
viewHolder.starItem.setOnClickListener{
LogUtils()
用于(0中的u,直到vChildrens!!.size){
val vChildrenn:View=vChildrens!![u]
视图持有者=视图持有者(视图=vChildrenn)
LogUtils().v(“item”,“${item.tag.toString().toInt()}”)
if(item.tag.toString().toInt()selectOn&&first){
**这里我想调用另一个类的类事件**
}
if(vChildrenn.tag.toString().toInt())请发布一些代码来重现该问题。我同意。我们需要知道CustomRateBar如何更新RateBottomSheet中的项目。您能否解释有关该功能的更多信息?ImageButton的可见性是否根据评级而改变?是的,您可以使用listener。使用布尔值作为参数,并在设置可见性时使用相同的参数。发布!请帮助我编写一些代码,我应该在侦听器中传递什么作为参数?