I am trying to spin a picture with a timer on touch event. I created a method which works without timer/thread. But When I use it in a timer, It doesnt work. I am not good in android programming.
———–> this is the ontouch event
@Override
public boolean onTouch(View v, MotionEvent event){
t1=new TimerTask()
{
public void run()
{
angle += 40;
spin(angle);
if(angle >=360)
angle = 0;
}
};
t.schedule(t1,2*1000);
return false;
}});
———-> and this is my spin method
public void spin(int degree)
{
Bitmap bMap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
Matrix mat = new Matrix();
mat.postRotate(degree);
Bitmap bMapRotate = Bitmap.createBitmap(bMap, 0, 0, bMap.getWidth(), bMap.getHeight(), mat, true);
bottle.setImageBitmap(bMapRotate);
}
Use
android.os.Handlerinstead of your timer like this-