0
私は、ユーザーが地図を長くクリックして、新しいタグと情報を追加するための新しいアクティビティを開くことができるアプリを作っています。ユーザーが一度長くクリックすると、十分に速い場合は、地図上を長く2回クリックすると2回目のアクティビティが2回開かれます。私はこの動作を無効にする方法を見つけることを試みています。私はすでにいくつかの例を試して、フラグを追加しようとしましたが効果はありませんでした。地図上の長いクリックで活性化する回数が増える
ロングクリックを2回無効にしたいと思います。私はまた、おそらくローダーを追加したいと思います。 ユーザーがすでに長い時間クリックして新しいアクティビティを開くと、新しいクリックが無効になったときにもう一度有効にすると、長いクリックが無効になります。
マイマップのフラグメントは次のようになります。
//Add marker on long click
mMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {
@Override
public void onMapLongClick(final LatLng arg0) {
RequestQueue queue = Volley.newRequestQueue(getActivity());
String url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + String.valueOf(arg0.latitude) + "," + String.valueOf(arg0.longitude) + "&key=myKey";
// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONArray jObj = new JSONObject(response).getJSONArray("results").getJSONObject(0).getJSONArray("address_components");
Intent intent = new Intent(getActivity(), AddRestaurantActivity.class);
for (int i = 0; i < jObj.length(); i++) {
String componentName = new JSONObject(jObj.getString(i)).getJSONArray("types").getString(0);
if (componentName.equals("postal_code") || componentName.equals("locality") || componentName.equals("street_number") || componentName.equals("route")
|| componentName.equals("neighborhood") || componentName.equals("sublocality") || componentName.equals("administrative_area_level_2")
|| componentName.equals("administrative_area_level_1") || componentName.equals("country")) {
intent.putExtra(componentName, new JSONObject(jObj.getString(i)).getString("short_name"));
}
}
intent.putExtra("latitude", arg0.latitude);
intent.putExtra("longitude", arg0.longitude);
startActivity(intent);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
int x = 1;
}
});
// Add the request to the RequestQueue.
queue.add(stringRequest);
}
});
そして、これは、それが開かれた活動であり、thisとthis答えとは、フラグを追加する(特に)試してみました:
private void setRestaurant(final String userId, final String message, final String pickDate, final String pickTime, final String location, final String lat, final String lon, final String sendTo, final boolean enableComments) {
// Tag used to cancel the request
String tag_string_req = "req_add_restaurant";
final String commentsEnabled = (enableComments) ? "0" : "1";
pDialog.setMessage(getString(R.string.setting_a_restaurant));
showDialog();
ApiInterface apiService =
ApiClient.getClient().create(ApiInterface.class);
Call<DefaultResponse> call = apiService.addrestaurant(userId, message, lat, lon, pickDate, pickTime, sendTo, commentsEnabled);
call.enqueue(new Callback<DefaultResponse>() {
@Override
public void onResponse(Call<DefaultResponse> call, retrofit2.Response<DefaultResponse> response) {
// Launch main activity
Intent intent = new Intent(SetRestaurantActivity.this,
MainActivity.class);
// I TRIED TO BLOCK IT HERE
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
// I ALSO TRIED:
// intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
finish();
Toast.makeText(getApplicationContext(), R.string.sucessfully_created_restaurant, Toast.LENGTH_LONG).show();
}
});
}
答えていただきありがとうございます。Saheb。これは特定の点に作用します。それは同時に開く2つのアクティビティを無効にしますが、私が2回ロングクリックすると新しいアクティビティが1回開きますが、閉じると再び開きます... – Kemo
isRequestProcessの代わりにProgressDialogを使用しました。 pd = ProgressDialog.show(これ、 ""、 "ロード中。しばらくお待ちください..."、true); //ダウンロードファイル pd.cancel(); ' – Kemo