Thanx for taking the time to look at the question. I am trying out some android programming and I have hit a wall; not sure how to solve it. I am trying activate an animation for a specific entity only when touch count is odd. That is touchCount%2 != 0.
public boolean onTouch(View v, MotionEvent event){
ArrayList<TextView> textToDance = new ArrayList<TextView>();
textToDance.add((TextView)findViewById(R.id.CAD5));
textToDance.add((TextView)findViewById(R.id.CAD10));
textToDance.add((TextView)findViewById(R.id.CAD20));
textToDance.add((TextView)findViewById(R.id.CAD50));
textToDance.add((TextView)findViewById(R.id.CAD100));
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
for(TextView txtAnimate: textToDance){
if(event.getRawX()<= txtAnimate.getX()+txtAnimate.getMeasuredWidth() && event.getRawX()>=txtAnimate.getX()){
if(event.getRawY()<= txtAnimate.getY()+105+txtAnimate.getMeasuredHeight() && event.getRawY()>=txtAnimate.getY()+105){
helpAnimate(txtAnimate, 0);
}
}
}
break;
case MotionEvent.ACTION_MOVE:
Log.d("MOVE","MOVE");
break;
case MotionEvent.ACTION_UP:
Log.d("UP","UP");
break;
default:
break;
}
return true;
}
I tried to implement a HashMap but that map gets reset everything onTouch is called. Any suggestions?
Firstly, you want to initialize your array outside of the
onTouchmethod.Then you could create a map and initialize it with zero count values and register an onTouchListener (let’s assume its your
Activity)Then in
onTouchyou would have something like…This probably isn’t the most optimal way but it should be enough to get you started with achieving the kind of thing you’re looking to do.