Im drawing an indoor map using DrawRect method. I want to identify each rectangle by the user's OnTouch Event.How can i make it happen?
I want to know if i can use the drawn Rectangles as independent objects Where i can identify them uniquely.
UPDATED
I tried this. But it gives me errors.How can i create a new intent withing the for loop?? :(
ArrayList<Rect> rectangles = new ArrayList<Rect>();
{rectangles.add(new Rect(232,78,419,238));
rectangles.add(new Rect(285,27,524,239));
rectangles.add(new Rect(418,79,524,239));
rectangles.add(new Rect(181,79,233,215));
rectangles.add(new Rect(232,237,524,315));}
String Selected_rect = null;
public boolean onTouchEvent(MotionEvent event) {
int touchX = (int) event.getX();
int touchY = (int) event.getY();
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
System.out.println("Touching down!");
for(int i =0; i< rectangles.size();i++){
if(rectangles.get(i).contains(touchX,touchY)){
System.out.println("Touched Rectangle, start activity.");
rectangles.get(i).describeContents ();
Selected_rect = String.valueOf(rectangles.get(i));
}
// Intent inte = new Intent("android.intent.action.DetectBlock");
// startActivity(inte);
}
break;
case MotionEvent.ACTION_UP:
System.out.println("Touching up!");
break;
case MotionEvent.ACTION_MOVE:
System.out.println("Sliding your finger around on the screen.");
break;
}
return true;
}
My Intent method body
private void startActivity(Intent inte) {
// TODO Auto-generated method stub
startActivity(inte);
}