Android 工作室点击 xy 坐标
Android studio click on coords x y
嗨,我想当我自动点击按钮时 button2 被 MotionEvent me = MotionEvent.obtain(SystemClock.uptimeMillis(),
SystemClock.uptimeMillis(),
MotionEvent.ACTION_DOWN,
500,
935,
0);
button=(Button)findViewById(R.id.boutton);
button2=(Button)findViewById(R.id.button2);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MotionEvent me = MotionEvent.obtain(SystemClock.uptimeMillis(),
SystemClock.uptimeMillis(),
MotionEvent.ACTION_DOWN,
500,
935,
0);
view.dispatchTouchEvent(me);
}
});
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this,"Clicled",Toast.LENGTH_LONG).show();
}
});
};
您需要使用 performClick()
方法来实现此目的,方法是在 button
的 onClickListener 中使用它
View.performClick();
请检查以下答案以获得更多理解:
How to simulate a button click using code?
Simulate Android button click programmatically
另请检查以下文档:
(https://developer.android.com/reference/android/view/View.html#performClick())
嗨,我想当我自动点击按钮时 button2 被 MotionEvent me = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, 500, 935, 0);
button=(Button)findViewById(R.id.boutton);
button2=(Button)findViewById(R.id.button2);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MotionEvent me = MotionEvent.obtain(SystemClock.uptimeMillis(),
SystemClock.uptimeMillis(),
MotionEvent.ACTION_DOWN,
500,
935,
0);
view.dispatchTouchEvent(me);
}
});
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this,"Clicled",Toast.LENGTH_LONG).show();
}
});
};
您需要使用 performClick()
方法来实现此目的,方法是在 button
View.performClick();
请检查以下答案以获得更多理解:
How to simulate a button click using code?
Simulate Android button click programmatically
另请检查以下文档: (https://developer.android.com/reference/android/view/View.html#performClick())