0
我做了什麼:我能夠使用this post模擬觸摸事件在一定間隔的Android
// Obtain MotionEvent object
view.setOnTouchListener(new OnTouchListener()
{
public boolean onTouch(View v, MotionEvent event)
{
Toast toast = Toast.makeText(
getApplicationContext(),
"View touched",
Toast.LENGTH_LONG
);
toast.show();
return true;
}
});
// Obtain MotionEvent object
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis() + 100;
float x = 0.0f;
float y = 0.0f;
// List of meta states found here: developer.android.com/reference/android/view/KeyEvent.html#getMetaState()
int metaState = 0;
MotionEvent motionEvent = MotionEvent.obtain(
downTime,
eventTime,
MotionEvent.ACTION_UP,
x,
y,
metaState
);
// Dispatch touch event to view
view.dispatchTouchEvent(motionEvent);
什麼,我試圖做模擬觸摸事件:
- 我哇nt以每5秒爲間隔模擬觸摸事件。
- 如何實現這個
試過了,收到錯誤無法裏面looper.prepare創建處理程序..... – Devrath
嘗試在UI線程。 Plz向我顯示了整個錯誤信息。 –