为surfaceview-Android添加回调的问题
我在单击按钮期间添加回调时遇到困难:为surfaceview-Android添加回调的问题,android,Android,我在单击按钮期间添加回调时遇到困难: protected void onCreate(Bundle savedInstanceState) { ...... //get the Image View at the main.xml file setIv_image((ImageView) findViewById(R.id.gimg1)); //get the Surface View at the main.xml file setSv((SurfaceView) findViewById
protected void onCreate(Bundle savedInstanceState) {
......
//get the Image View at the main.xml file
setIv_image((ImageView) findViewById(R.id.gimg1));
//get the Surface View at the main.xml file
setSv((SurfaceView) findViewById(R.id.testin));
//Get a surface
setsHolder(getSv().getHolder());
// SET CALLBACK
setCalling((Callback) this);
.......
takeImage.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
//add the callback interface methods defined below as the Surface View callbacks
getsHolder().addCallback(getCalling());
//tells Android that this surface will have its data constantly replaced
getsHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
});
.....My functions to work for the surfaceview
现在,我只需删除getsHolder.addCallbackgetCalling,它就可以完美地工作了;并将其移动到setOnClickListener外部的上方
我的问题是我希望它在我的按钮被点击时工作,但是如果我在点击事件中有它,它就不能正常工作
想法和建议?使用以下方法调用getsHolder
takeImage.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//add the callback interface methods defined below as the Surface View callbacks
this.getsHolder().addCallback(getCalling());
//tells Android that this surface will have its data constantly replaced
this.getsHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
});