android:onclick="selftDestruct ",运行时出现找不到selftDestruct方法的错误,求大神指教! androidsdkxml 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我就不跟你说原理了, 你可以自己去探究,我告诉你问题所在的原因:1.在使用Fragment的时候,所有监听事件,都必须find出来,并且setonClicklistener2.如:该Fragment实现OnClickListener接口,在onViewCreated方法中view.findViewById(R.id.button1).setOnClickListener(this);接下来的OnClick就生效了 你的selftDestruct(View view)这个方法应该要写在加载这个view的activity的类里面参考view初始化的代码View.java case R.styleable.View_onClick: if (context.isRestricted()) { throw new IllegalStateException("The android:onClick attribute cannot " + "be used within a restricted context"); } final String handlerName = a.getString(attr); if (handlerName != null) { setOnClickListener(new OnClickListener() { private Method mHandler; public void onClick(View v) { if (mHandler == null) { try { mHandler = getContext().getClass().getMethod(handlerName, View.class); } catch (NoSuchMethodException e) { int id = getId(); String idText = id == NO_ID ? "" : " with id '" + getContext().getResources().getResourceEntryName( id) + "'"; throw new IllegalStateException("Could not find a method " + handlerName + "(View) in the activity " + getContext().getClass() + " for onClick handler" + " on view " + View.this.getClass() + idText, e); } } try { mHandler.invoke(getContext(), View.this); } catch (IllegalAccessException e) { throw new IllegalStateException("Could not execute non " + "public method of the activity", e); } catch (InvocationTargetException e) { throw new IllegalStateException("Could not execute " + "method of the activity", e); } } }); } break; 应该是1楼的说法,fragment不能像activity那样直接写事件 为什么菜单不显示? 请问如何调用系统闹钟?? View 重写增加 scrollbar android如何在程序中往sqlite数据库建表? 下面这段代码如何改成对应的类? onLongPress手势不能识别 各位牛人,为什么在2.3上正常工作的拍照应用在4.3上崩溃? 从内存卡读取图片,放到list里面,再放进adapte里面出错啦 android大神求救,关于底部弹出菜单的问题 为什么sqlLite创不了表,代码在下面,求大神帮我看看 eclipse DDMS File Explorer不能展开sdcard文件夹 Pull解析器,解析网页出现意外
1.在使用Fragment的时候,所有监听事件,都必须find出来,并且setonClicklistener
2.如:该Fragment实现OnClickListener接口,在onViewCreated方法中
view.findViewById(R.id.button1).setOnClickListener(this);
接下来的OnClick就生效了
参考view初始化的代码View.java case R.styleable.View_onClick:
if (context.isRestricted()) {
throw new IllegalStateException("The android:onClick attribute cannot "
+ "be used within a restricted context");
} final String handlerName = a.getString(attr);
if (handlerName != null) {
setOnClickListener(new OnClickListener() {
private Method mHandler; public void onClick(View v) {
if (mHandler == null) {
try {
mHandler = getContext().getClass().getMethod(handlerName,
View.class);
} catch (NoSuchMethodException e) {
int id = getId();
String idText = id == NO_ID ? "" : " with id '"
+ getContext().getResources().getResourceEntryName(
id) + "'";
throw new IllegalStateException("Could not find a method " +
handlerName + "(View) in the activity "
+ getContext().getClass() + " for onClick handler"
+ " on view " + View.this.getClass() + idText, e);
}
} try {
mHandler.invoke(getContext(), View.this);
} catch (IllegalAccessException e) {
throw new IllegalStateException("Could not execute non "
+ "public method of the activity", e);
} catch (InvocationTargetException e) {
throw new IllegalStateException("Could not execute "
+ "method of the activity", e);
}
}
});
}
break;