[英]Unresolved reference: findViewById on SnackBar
Am trying to add a SnackBar that is called when Delete is clicked however I am getting the error 'Unresolved reference: findViewById' when I add the Scackbar to the Delete Menu我正在尝试添加一个在单击删除时调用的 SnackBar,但是当我将 Scackbar 添加到删除菜单时出现错误“未解决的参考:findViewById”
holder.menu.setOnClickListener {
val popup = PopupMenu(activity,holder.menu)
popup.inflate(R.menu.dashboard_child)
popup.setOnMenuItemClickListener {
when(it.itemId){
R.id.menu_edit->{
activity.updateToDo(list[p1])
}
R.id.menu_delete->{
activity.dbHandler.deleteToDo(list[p1].id)
activity.refreshList()
val mySnackbar = Snackbar.make(
findViewById(R.id.myCoordinatorLayout),
R.string.task_deleted, Snackbar.LENGTH_SHORT
)
mySnackbar.setAction(R.string.undo_string, MyUndoListener())
mySnackbar.show()
}
}
true
}
popup.show()
}
Try this to show snackbar试试这个来显示小吃吧
val snackbar = Snackbar.make(activity.findViewById(android.R.id.content), R.string.task_deleted, Snackbar.LENGTH_SHORT)
snackbar .setAction(R.string.undo_string, MyUndoListener())
snackbar.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.