在我的应用程序中,我有一个弹出菜单,当我单击菜单项时它会收集 gps 位置,问题是当我双击菜单时它会触发两次但我只执行 onclick 不确定我在哪里做错了
LinearLayout popupmain = (LinearLayout) view
.findViewById(R.id.popupmain);
ImageView popupImage = (ImageView) view.findViewById(R.id.popupimg);
TextView popupName = (TextView) view.findViewById(R.id.popupname);
popupImage.setImageResource(popUpMenu.getImageResource());
popupName.setText(popUpMenu.getMenuName());
popupName.setTag(popUpMenu);
popupmain.setTag(popUpMenu);
popupName.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
doAction(v, activity);
}
});
popupmain.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
doAction(v, activity);
}
});
return view;
}
public void doAction(View v, Activity activity) {
Context myContext = v.getContext();
PopUpMenu popUpMenu = (PopUpMenu) v.getTag();
String result = popUpMenu.getMenuName();
if (result != null
&& result.equalsIgnoreCase(myContext.getResources().getString(
R.string.savecurrentlocation))) {
getLocation();
}
private void getLocation() {
manager = (LocationManager) parentActivity
.getSystemService(Context.LOCATION_SERVICE);
listener = new ManageLocation();
listener.setSucessCallBack(this, "setLocation");
listener.setFailureCallBack(this, "setNoLocation");
manager.requestLocationUpdates(
new Utils().getCurrentPlaceLocationProvider(manager), 0, 0,
listener);
}
任何帮助表示赞赏。
我的弹出主 xml 文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/popupmain"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="5dp" >
<ImageView
android:id="@+id/popupimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/popupname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="8dp"
android:text="@string/default_date"
android:textColor="#000000"
android:textSize="15dp"
android:typeface="serif" />
</LinearLayout>
</LinearLayout>