活动:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cool); //layout with button and custom view
myNewView myView = new myNewView(this); // create custom view
button = (Button) findViewById(R.id.btn_1);
button.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
String t = myView.do_smth(); ///HERE is NOT working
}
});
}
自定义视图:
public class myNewView extends View {
public myNewView(Context context) {
super(context);
initialize();
}
public String do_smth() {
String t = "";
t = "34";
return t;
}
}
所以 t 变量为空。这段代码有什么问题?如果您想了解更多详细信息,请告诉我。