Android——用户点击的地方——找到确切的位置
我正在开发一个新的android应用程序,它将首先向用户显示一个Android——用户点击的地方——找到确切的位置,android,dictionary,user-controls,user-input,Android,Dictionary,User Controls,User Input,我正在开发一个新的android应用程序,它将首先向用户显示一个国家地图,然后用户可以从地图中选择一个省份。所以问题是如何找出用户的选择 例如:我显示下面的地图,用户选择那不勒斯,那么我如何才能找到用户单击的那不勒斯 我在谷歌上找不到关于这个问题的任何信息,有人能帮我吗?使用onTouchEvent()方法。您将收到MotionEvent作为参数,因此我要做的是: @Override public boolean onTouchEvent(MotionEvent event) { in
国家地图
,然后用户可以从地图中选择一个省份
。所以问题是如何找出用户的选择
例如:我显示下面的地图,用户选择那不勒斯
,那么我如何才能找到用户单击的那不勒斯
我在谷歌上找不到关于这个问题的任何信息,有人能帮我吗?使用onTouchEvent()方法。您将收到MotionEvent作为参数,因此我要做的是:
@Override
public boolean onTouchEvent(MotionEvent event) {
int action = event.getAction();
int x = Math.round(event.getX());
int y = Math.round(event.getY());
//x and y are the coordinates of the touched location
switch (action) {
case MotionEvent.ACTION_DOWN:
//If the touch was a down press
/* if the coordinates x and y fall within the imageView/Bitmap
(not sure which you are using) then perform whatever action
you want */
}
return true;
}
这是一项活动还是一项表面观察?这只是一项活动嗯,是的,你可以通过这种方式获得这个职位。但是在活动上画地图怎么样?