我正在寻找一种方式,当用户长时间触摸mapview(比方说1000ms),我可以做一些特定的动作.
我将如何判断用户长时间触摸mapsview(或任何视图)的时间.
这将类似于Android谷歌地图应用程序,当你长时间触摸,它会带来气球覆盖项目.
编辑已添加
mapView.setOnLongClickListener(new View.OnLongClickListener() {
public boolean onLongClick(View v) {
Toast.makeText(mapView.getContext(), "Hello 123", 2000);
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
以上不起作用......任何想法为什么?
这就是我现在正在尝试的,但它似乎不起作用,即使我只按手机,它说这个事件是一个action_move,
我在MapActivity中使用内部类
private long startTime=0;
private long endTime=0;
class MapOverlay extends Overlay {
@Override
public boolean onTouchEvent(MotionEvent ev, MapView mapView) {
if(ev.getAction() == MotionEvent.ACTION_DOWN){
//record the start time
startTime = ev.getEventTime();
Log.d("LC", "IN DOWN");
}else if(ev.getAction() == MotionEvent.ACTION_UP){
//record the end time
endTime = ev.getEventTime();
Log.d("LC", "IN UP");
}else if(ev.getAction() == MotionEvent.ACTION_MOVE){
Log.d("LC", "IN move");
endTime=0;
}
//verify …Run Code Online (Sandbox Code Playgroud) 我有3个布局,我需要点击按钮访问某些布局和广告从中删除控件任何想法如何实现,这是我使用的代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.20"
android:orientation="horizontal" >
<Button
android:id="@+id/backbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Back" />
<Button
android:id="@+id/backbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="next" />
</LinearLayout>
<!-- the two columns part -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.80"
android:orientation="horizontal" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.80" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First Name" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.20" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="second Name" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)