单击按钮会在单击按钮重复时重复打开新活动。如何避免这种情况

时间:2018-03-22 07:41:56

标签: android button android-intent

我对Android开发很新。在我的应用程序中,我使用一个对话框提交一个表单。按钮单击按钮后提交按钮只有一次它完美的工作。但我一直点击它反复提交并反复打开新活动。为解决这个问题,我使用了意图标志。但问题仍然存在。以下是提交对话框的代码。

private void report_abuse(final String report_text) {
    db = new SQLiteHandler(getApplicationContext());
    HashMap<String, String> user = db.getUserDetails();
    final String user_id = user.get("uid");
    final String token = user.get("token");
    Intent get_id = getIntent();
    final String profile_id = get_id.getStringExtra("reg_id");

    String tag_string_req = "req_register";

    StringRequest strReq = new StringRequest(Request.Method.POST,
    URL_REPORT_ABUSE, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {

            try {
                JSONObject jObj = new JSONObject(response);
                boolean error = jObj.getBoolean("error");
                if (!error) {
                    Intent to_profile = new Intent(ProfileView.this, ProfileView.class);
                    to_profile.putExtra("reg_id", profile_id);
                    startActivity(to_profile);
                    finish();
                    Toast.makeText(getApplicationContext(),
                        "report submit successfully", Toast.LENGTH_LONG).show();
                } else {
                    String errorMsg = jObj.getString("error_msg");
                    Toast.makeText(getApplicationContext(), errorMsg, Toast.LENGTH_LONG).show();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e(TAG, "Registration Error: " + error.getMessage());
            Toast.makeText(getApplicationContext(),
            error.getMessage(), Toast.LENGTH_LONG).show();
            //hideDialog();
        }
    }) {
        @Override
        protected Map<String, String> getParams() {
        Map<String, String> params = new HashMap<String, String>();
        params.put("user_id", user_id);
        params.put("profile_id", profile_id);
        params.put("message", report_text);
        return params;
    }
    @Override
    public Map<String, String> getHeaders() throws AuthFailureError {
        Map headers = new HashMap();
        headers.put("Client-Service", "app-client");
        headers.put("Auth-Key", "123321");
        headers.put("Token", token);
        headers.put("User-Id", user_id);
        return headers;
    }
};
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
}
});
mBuilder.setView(mView);
AlertDialog dialog = mBuilder.create();
dialog.show();
}
});

1 个答案:

答案 0 :(得分:1)

您只需要在第一次点击后点击的视图中调用view.setClickable(false)。