Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 刷卡查看id刷卡时如何发送到截击服务器_Android - Fatal编程技术网

Android 刷卡查看id刷卡时如何发送到截击服务器

Android 刷卡查看id刷卡时如何发送到截击服务器,android,Android,我正在开发一个用于求职的android应用程序。我用刷卡库看了很多工作,比如Tinder。在这里,我使用PHP JSON获取所有作业。 每个作业都有不同的id。如果要应用作业用户id和发送到服务器的作业id。用户id可以使用共享首选项发送到服务器。但刷卡正确时如何发送工作id。我试了很多方法。但这行不通。请帮帮我。如蒙帮助,我们将不胜感激 try { JSONArray jsonArray = new JSONArray(data); a

我正在开发一个用于求职的android应用程序。我用刷卡库看了很多工作,比如Tinder。在这里,我使用PHP JSON获取所有作业。 每个作业都有不同的id。如果要应用作业用户id和发送到服务器的作业id。用户id可以使用共享首选项发送到服务器。但刷卡正确时如何发送工作id。我试了很多方法。但这行不通。请帮帮我。如蒙帮助,我们将不胜感激

try {

              JSONArray jsonArray = new JSONArray(data);


            arrayList.clear();
            for (int i = 0; i<jsonArray.length(); i++){
                getData pd = new getData();
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                pd.setJob_title(jsonObject.getString("job_title"));
                pd.setJob_type(jsonObject.getString("job_type"));
                pd.setJob_description(jsonObject.getString("job_description"));
                pd.setAddress(jsonObject.getString("address"));
                pd.setCity(jsonObject.getString("city"));

                pd.setJob_id(jsonObject.getString("job_id"));




                arrayList.add(pd);

            }
适配器类

TextView tv_title = (TextView)v.findViewById(R.id.cardviewjobheading);
        TextView tv_description= (TextView)v.findViewById(R.id.cardviewJobDescription);
        TextView tv_jobtype = (TextView)v.findViewById(R.id.cardviewJobTime);
        TextView tv_companyadress = (TextView)v.findViewById(R.id.cardviewcompanyname);
        TextView tv_companycity = (TextView)v.findViewById(R.id.cardviewcompanyaddress);
        TextView tv_jobid=(TextView)v.findViewById(R.id.cardviewjobid);
        tv_title .setText(data.get(position).getJob_title().toString());
        tv_jobtype.setText(data.get(position).getJob_type().toString());
        tv_description.setText(data.get(position).getJob_description().toString());
        tv_companyadress.setText(data.get(position).getAddress().toString());
        tv_companycity.setText(data.get(position).getCity().toString());
        tv_jobid.setText(data.get(position).getJob_id().toString());
         String  id=data.get(position).getJob_id().toString();
    //    Toast.makeText(context,id,Toast.LENGTH_LONG).show();

        SharedPreferences.Editor editor = context.getSharedPreferences(Config.SHARED_PREF_NAME, MODE_PRIVATE).edit();
        editor.putString("jobId",id);
        editor.apply();
主要活动

@Override
            public void cardSwipedRight( int position) {

                 saveinformation();



            }
private  void saveinformation() {







        pDialog = new ProgressDialog(this);
        pDialog.setMessage("Please wait...");
        pDialog.setCancelable(false);
        pDialog.show();


        StringRequest stringRequest = new StringRequest(Request.Method.POST, Config.URL_APPLYJOB,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String ServerResponse) {

                        // Hiding the progress dialog after all task complete.
                        pDialog.dismiss();
                        try {
                            JSONObject jsonObject = new JSONObject(ServerResponse);


                            if (jsonObject.getInt("success") == 0) {

                                Toast.makeText(getApplicationContext(), jsonObject.getString("message"), Toast.LENGTH_LONG).show();

                            } else if (jsonObject.getInt("success") == 1) {
                               // Toast.makeText(getApplicationContext(), jsonObject.getString("message"), Toast.LENGTH_LONG).show();
                                MaterialToast materialToast=new MaterialToast(MainActivity.this);
                                materialToast.show(jsonObject.getString("message"), ContextCompat.getDrawable(MainActivity.this,R.drawable.toast_drawable),
                                        ContextCompat.getColor(MainActivity.this,R.color.colorAccent),
                                        Gravity.CENTER_HORIZONTAL);
                                } else

                                Toast.makeText(getApplicationContext(), jsonObject.getString("message"), Toast.LENGTH_LONG).show();
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {


                        pDialog.dismiss();


                        MaterialToast materialToast=new MaterialToast(MainActivity.this);
                        materialToast.show("Check Internet Connection", ContextCompat.getDrawable(MainActivity.this,R.drawable.toast_drawable),
                                ContextCompat.getColor(MainActivity.this,R.color.colorAccent),
                                Gravity.CENTER_HORIZONTAL);
                    }
                }) {
            @Override
            protected Map<String, String> getParams() {

                // Creating Map String Params.
                Map<String, String> params = new HashMap<String, String>();

                // Adding All values to Params.
                SharedPreferences prefs = getApplicationContext().getSharedPreferences(Config.SHARED_PREF_NAME, Context.MODE_PRIVATE);
                String userid = prefs.getString("userId","");
                String jobid =  prefs.getString("jobId","");





                params.put("user_id",userid);

                params.put("job_id",jobid);

                return params;
            }

        };


        RequestQueue requestQueue = Volley.newRequestQueue(this);
        requestQueue.add(stringRequest);


    }
@覆盖
公共作废卡片向右(内部位置){
保存信息();
}
私有void saveinformation(){
pDialog=新建进度对话框(此对话框);
setMessage(“请稍候…”);
pDialog.setCancelable(假);
pDialog.show();
StringRequest StringRequest=新建StringRequest(Request.Method.POST,Config.URL\u APPLYJOB,
新的Response.Listener(){
@凌驾
公共void onResponse(字符串ServerResponse){
//在所有任务完成后隐藏进度对话框。
pDialog.disclose();
试一试{
JSONObject JSONObject=新的JSONObject(ServerResponse);
if(jsonObject.getInt(“成功”)==0){
Toast.makeText(getApplicationContext(),jsonObject.getString(“消息”),Toast.LENGTH\u LONG.show();
}else if(jsonObject.getInt(“成功”)==1){
//Toast.makeText(getApplicationContext(),jsonObject.getString(“消息”),Toast.LENGTH\u LONG.show();
MaterialToast MaterialToast=新的MaterialToast(主活动。此);
materialToast.show(jsonObject.getString(“消息”),ContextCompat.getDrawable(MainActivity.this,R.drawable.toast\u drawable),
getColor(MainActivity.this,R.color.colorAccent),
重心(水平);
}否则
Toast.makeText(getApplicationContext(),jsonObject.getString(“消息”),Toast.LENGTH\u LONG.show();
}捕获(JSONException e){
e、 printStackTrace();
}
}
},
新的Response.ErrorListener(){
@凌驾
公共错误响应(截击错误截击错误){
pDialog.disclose();
MaterialToast MaterialToast=新的MaterialToast(主活动。此);
materialToast.show(“检查互联网连接”,ContextCompat.getDrawable(MainActivity.this,R.drawable.toast\u drawable),
getColor(MainActivity.this,R.color.colorAccent),
重心(水平);
}
}) {
@凌驾
受保护的映射getParams(){
//正在创建映射字符串参数。
Map params=新的HashMap();
//将所有值添加到参数。
SharedReferences prefs=getApplicationContext().GetSharedReferences(Config.SHARED\u PREF\u NAME,Context.MODE\u PRIVATE);
字符串userid=prefs.getString(“userid”,“userid”);
String jobid=prefs.getString(“jobid”,”);
参数put(“用户id”,userid);
参数put(“作业id”,作业id);
返回参数;
}
};
RequestQueue RequestQueue=Volley.newRequestQueue(this);
添加(stringRequest);
}

不要使用SharedReference,只需使用您在cardSwipedRight()中获得的位置即可。使用该位置,使用arraylist.get(位置)从arraylist获取特定项。 然后使用返回的对象,并获取两个ID。 然后将这些值传递给该截击方法


**不建议为此目的使用SharedReference。

从服务器获取的作业id工作正常。我想将该作业id传递给服务器
@Override
            public void cardSwipedRight( int position) {

                 saveinformation();



            }
private  void saveinformation() {







        pDialog = new ProgressDialog(this);
        pDialog.setMessage("Please wait...");
        pDialog.setCancelable(false);
        pDialog.show();


        StringRequest stringRequest = new StringRequest(Request.Method.POST, Config.URL_APPLYJOB,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String ServerResponse) {

                        // Hiding the progress dialog after all task complete.
                        pDialog.dismiss();
                        try {
                            JSONObject jsonObject = new JSONObject(ServerResponse);


                            if (jsonObject.getInt("success") == 0) {

                                Toast.makeText(getApplicationContext(), jsonObject.getString("message"), Toast.LENGTH_LONG).show();

                            } else if (jsonObject.getInt("success") == 1) {
                               // Toast.makeText(getApplicationContext(), jsonObject.getString("message"), Toast.LENGTH_LONG).show();
                                MaterialToast materialToast=new MaterialToast(MainActivity.this);
                                materialToast.show(jsonObject.getString("message"), ContextCompat.getDrawable(MainActivity.this,R.drawable.toast_drawable),
                                        ContextCompat.getColor(MainActivity.this,R.color.colorAccent),
                                        Gravity.CENTER_HORIZONTAL);
                                } else

                                Toast.makeText(getApplicationContext(), jsonObject.getString("message"), Toast.LENGTH_LONG).show();
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {


                        pDialog.dismiss();


                        MaterialToast materialToast=new MaterialToast(MainActivity.this);
                        materialToast.show("Check Internet Connection", ContextCompat.getDrawable(MainActivity.this,R.drawable.toast_drawable),
                                ContextCompat.getColor(MainActivity.this,R.color.colorAccent),
                                Gravity.CENTER_HORIZONTAL);
                    }
                }) {
            @Override
            protected Map<String, String> getParams() {

                // Creating Map String Params.
                Map<String, String> params = new HashMap<String, String>();

                // Adding All values to Params.
                SharedPreferences prefs = getApplicationContext().getSharedPreferences(Config.SHARED_PREF_NAME, Context.MODE_PRIVATE);
                String userid = prefs.getString("userId","");
                String jobid =  prefs.getString("jobId","");





                params.put("user_id",userid);

                params.put("job_id",jobid);

                return params;
            }

        };


        RequestQueue requestQueue = Volley.newRequestQueue(this);
        requestQueue.add(stringRequest);


    }