Make a blank area clickable in android and then make an image appear over
the area clicked
Can anyone tell me please how can I make the whole blank screen clickable
on the android ? Means wherever I can click on it and then the place where
i click there one particular image has to appear where i can then make the
notes. I am trying to first find the coordinates of that area and then
putting the image. But i am not able to find the code for doing that.
Means after finding the coordinates what can be done?
Or if there is some other way then also please help with that!!
For finding coordinates:
public class MainActivity extends Activity implements OnTouchListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView xCoord = (TextView) findViewById(R.id.button1);
final TextView yCoord = (TextView) findViewById(R.id.button2);
final View touchView = findViewById(R.id.button3);
touchView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
final int action = event.getAction();
switch (action & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN: {
xCoord.setText(String.valueOf((int) event.getX()));
yCoord.setText(String.valueOf((int) event.getY()));
break;
}
case MotionEvent.ACTION_MOVE:{
xCoord.setText(String.valueOf((int) event.getX()));
yCoord.setText(String.valueOf((int) event.getY()));
break;
}
}
return true;
}
});
}
No comments:
Post a Comment