我要在单击按钮时打开一个对话框。但是我需要在此事件之前和之后执行逻辑。该怎么办?
我尝试过的事情:
模板
Add
脚本
public static int Add (int num01, int num02){
//Console if need
return num01 + num02;
}
这似乎是一个不好的解决方法,因为毕竟所有的v插槽仍然存在。
答案 0 :(得分:-1)
在第一个示例中,您实际上并不需要使用props.handleChange
-无需激活import android.view.ScaleGestureDetector;
public class MainActivity extends AppCompatActivity {
ImageView im1;
private ScaleGestureDetector mScaleGestureDetector;
private float mScaleFactor = 1.0f;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
im1=(ImageView)findViewById(R.id.im1);
mScaleGestureDetector = new ScaleGestureDetector(this, new ScaleListener());
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return mScaleGestureDetector.onTouchEvent(event);
}
private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
// when a scale gesture is detected, use it to resize the image
@Override
public boolean onScale(ScaleGestureDetector scaleGestureDetector){
mScaleFactor *= scaleGestureDetector.getScaleFactor();
im1.setScaleX(mScaleFactor);
im1.setScaleY(mScaleFactor);
return true;
}
}
}
标签(as described in the "Without activator" example here)。
但是,对我个人而言,推荐的方法是您提供的第二个示例-使用 private float spacing(MotionEvent event)
{
float x = event.getX(0) - event.getX(1);
float y = event.getY(0) - event.getY(1);
return (float) Math.sqrt(x * x + y * y);
}
触发对话框的示例,因为它处理打开对话框而无需编写额外的功能来设置您的其中一个private void midPoint(PointF point, MotionEvent event)
{
float x = event.getX(0) + event.getX(1);
float y = event.getY(0) + event.getY(1);
point.set(x / 2, y / 2);
}
个变量。