カスタム GalleryView を作成し、自分のデバイス (Samsung Galaxy S III & Nexus 4) で動作しますが、エミュレータで使用しようとすると、次のエラーが発生しました!!!
02-24 01:01:03.593: E/AndroidRuntime(3429): FATAL EXCEPTION: Thread-11
02-24 01:01:03.593: E/AndroidRuntime(3429): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
02-24 01:01:03.593: E/AndroidRuntime(3429): at android.view.ViewRoot.checkThread(ViewRoot.java:2802)
02-24 01:01:03.593: E/AndroidRuntime(3429): at android.view.ViewRoot.playSoundEffect(ViewRoot.java:2581)
02-24 01:01:03.593: E/AndroidRuntime(3429): at android.view.View.playSoundEffect(View.java:8516)
02-24 01:01:03.593: E/AndroidRuntime(3429): at android.widget.Gallery.onKeyDown(Gallery.java:1109)
02-24 01:01:03.593: E/AndroidRuntime(3429): at com.example.coverflow.ui.galleryView$1.run(galleryView.java:55)
02-24 01:01:03.593: E/AndroidRuntime(3429): at java.lang.Thread.run(Thread.java:1096)
これらのエラーは、私のコードの次の行に言及しています:
public void startSlideShow(final int periodTime)
{
final Runnable __runnable = new Runnable()
{
@Override
public void run()
{
if (!isTouched)
galleryView.this.onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT, null);
mHandler.postDelayed(this, periodTime);
}
};
new Thread(__runnable).start();
this.setOnTouchListener(new View.OnTouchListener()
{
@Override
public boolean onTouch(View view, MotionEvent event)
{
int currentEvent = event.getAction();
if (currentEvent == MotionEvent.ACTION_DOWN
|| currentEvent == MotionEvent.ACTION_MOVE)
isTouched = true;
else
{
isTouched = false;
// Reset handler
mHandler.removeCallbacks(__runnable);
mHandler.postDelayed(__runnable, periodTime);
}
return false;
}
});
}
55行目は galleryView.this.onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT, null);
この問題を回避するにはどうすればよいですか?