2014-02-25 23 views
0

我有困難的按鈕點擊過程中添加callback問題增加了回調的surfaceview - 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(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().addCallback(getCalling());並移動其上方的setOnClickListener...

之外

我的問題是我希望它在我的按鈕被點擊時工作,但它不能正常工作,如果我有它在點擊事件。

想法建議?

回答

-1

呼叫getsHolder()使用this如下...

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); 
     } 
    });