我有一个CustomDialog
我在上面使用了数百个 TextViews
与 onClick
属性,现在我想访问这些 onClick
Activity class
中的方法。这样CustomDialog
从 Activity
膨胀我想访问 onClick
的类方法,所以当我为 onClick
创建方法时喜欢
public void playerEdit(View view) {
Toast.makeText(this,"hello",Toast.LENGTH_LONG).show();
}
显然它会抛出 Exception
这是
Could not find a method playeEdit(View) in the activity class android.view.ContextThemeWrapper for onClick handler on view class android.widget.TextView with id 'p1'
这意味着我试图在不可访问的类中获取它,
我的问题是如何在 Activity Class
中访问它?
我该如何处理这个Exception
?
提前非常感谢...
最佳答案
您的 xml 文件中可能有拼写错误。方法名称是“playeEdit”而不是“playerEdit”
关于java - Android:如何访问 Activity 类中的非 Activity Xml onClick 属性方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24617406/