这让我发疯了......
我想用按钮构造函数传递一些参数
我确实创建了 myButton 扩展按钮:
package com.canbluetoothinterface.utilities;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import android.view.View.OnClickListener;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class myActivityStartButton extends Button implements OnClickListener {
protected EditText[] Array;
private String Name;
private String BufferName;
private Activity activityinstance;
public String[] sValues;
Class<?> cls;
private Method m;
public myActivityStartButton(String Name, Class<?>clsin, Context context) {
super(context);
cls = clsin;
activityinstance = (Activity) context;
setId(mygetId());
this.Name = Name;
init();
}
private void init(){
setOnClickListener(this);
}
public myActivityStartButton(String Name, Class<?>clsin, Context context, Method min) {
super(context);
this.cls = clsin;
this.Name = Name;
this.m = min;
activityinstance = (Activity) context;
setId(mygetId());
setTag(findViewById(mygetId()));
init();
}
@Override
public void setId(int id) {
super.setId(id);
}
private int mygetId() {
int id = 0;
BufferName = Name;
id = activityinstance.getResources().getIdentifier(BufferName, "id", activityinstance.getPackageName());
return id;
}
@Override
public void onClick(View v) {
try {
m.invoke(null, (Object)null);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Intent intent = new Intent(activityinstance, cls );
activityinstance.startActivity(intent);
}
}
在我的活动中,我调用:
Start = new myActivityStartButton("act_testdriveconfiguration_btn_start", DeviceListActivity.class, this, mstartbutton);
但是我的 OnClick 永远不会被调用......我做错了什么?
谢谢