使用截击从android向php发送数据
发送到服务器端的变量似乎无法到达服务器端,我无法找出问题所在。我从PHP脚本中得到一个响应,说帖子是空的 它应该如何工作使用截击从android向php发送数据,php,android,Php,Android,发送到服务器端的变量似乎无法到达服务器端,我无法找出问题所在。我从PHP脚本中得到一个响应,说帖子是空的 它应该如何工作 在警报对话框中插入注释 id和注释都必须发布到服务器端 请帮忙 @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { /* Alert Dialog
- 在警报对话框中插入注释
- id和注释都必须发布到服务器端
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
/* Alert Dialog Code Start*/
AlertDialog.Builder alert = new AlertDialog.Builder(context);
final String id_number =((TextView)view.findViewById(R.id.textViewIdnum)).getText().toString();
alert.setTitle("Alert id: "+id_number); //Set Alert dialog title here
alert.setMessage("Enter Your Comment here"); //Message here
// Set an EditText view to get user input
final EditText input = new EditText(context);
alert.setView(input);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// convert the input to a string and show in a toast.
String reason = input.getEditableText().toString();
Toast.makeText(SearchActivity.this,"Commenting...", Toast.LENGTH_LONG).show();
final String reason_key = input.getText().toString().trim();
//final String id_number_key = textview;
StringRequest stringRequest = new StringRequest(Request.Method.POST, Config.RESULT_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(SearchActivity.this,response,Toast.LENGTH_LONG).show();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(SearchActivity.this,error.toString(),Toast.LENGTH_LONG).show();
}
});
Map<String,String> params = new HashMap<String, String>();
params.put(TAG_IDNUM,id_number);
params.put(reason_key,reason);
RequestQueue requestQueue = Volley.newRequestQueue(SearchActivity.this);
requestQueue.add(stringRequest);
} // End of onClick(DialogInterface dialog, int whichButton)
}); //End of alert.setPositiveButton
alert.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
Toast.makeText(SearchActivity.this,"Commenting cancled",Toast.LENGTH_LONG).show();
dialog.cancel();
}
}); //End of alert.setNegativeButton
AlertDialog alertDialog = alert.create();
alertDialog.show();
/* Alert Dialog Code End*/
// End of onClick(View v)
}
});}
catch (JSONException e){}
}
@覆盖
public void onItemClick(AdapterView父对象、视图、整型位置、长id){
/*警报对话框代码启动*/
AlertDialog.Builder alert=新建AlertDialog.Builder(上下文);
最终字符串id_number=((TextView)view.findViewById(R.id.textViewIdnum)).getText().toString();
setTitle(“警报id:+id\U编号);//在此处设置警报对话框标题
alert.setMessage(“在此处输入注释”);//此处输入注释
//设置EditText视图以获取用户输入
最终编辑文本输入=新编辑文本(上下文);
alert.setView(输入);
alert.setPositiveButton(“确定”,新的DialogInterface.OnClickListener(){
public void onClick(对话框接口对话框,int whichButton){
//将输入转换为字符串并显示在toast中。
字符串原因=输入.getEditableText().toString();
Toast.makeText(SearchActivity.this,“评论…”,Toast.LENGTH_LONG.show();
最后一个字符串reason_key=input.getText().toString().trim();
//最终字符串id\u number\u key=textview;
StringRequest StringRequest=新的StringRequest(Request.Method.POST,Config.RESULT\u URL,
新的Response.Listener(){
@凌驾
公共void onResponse(字符串响应){
Toast.makeText(SearchActivity.this,response,Toast.LENGTH_LONG.show();
}
},
新的Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
Toast.makeText(SearchActivity.this,error.toString(),Toast.LENGTH_LONG.show();
}
});
Map params=新的HashMap();
参数put(标签号、id号);
参数put(原因键,原因);
RequestQueue RequestQueue=Volley.newRequestQueue(SearchActivity.this);
添加(stringRequest);
}//onClick(DialogInterface对话框,int whichButton)结束
});//警报结束。setPositiveButton
alert.setNegativeButton(“取消”,新建DialogInterface.OnClickListener()){
public void onClick(对话框接口对话框,int whichButton){
//取消了。
Toast.makeText(SearchActivity.this,“注释取消”,Toast.LENGTH_LONG.show();
dialog.cancel();
}
});//警报结束。setNegativeButton
AlertDialog AlertDialog=alert.create();
alertDialog.show();
/*警报对话框代码结束*/
//onClick结束(视图v)
}
});}
catch(JSONException e){}
}
首先,您需要测试php代码是否正常工作,使用postman测试您的“api”,如果它与postman一起工作,那么您的代码应该正常工作
在我看来,这与其说是android的失败,不如说是php的失败
你的
Toast.makeText(SearchActivity.this,response,Toast.LENGTH_LONG).show();
打印一些东西?首先,如果您需要测试php代码是否正常工作,请使用postman测试您的“api”,如果它与postman一起工作,那么您的代码应该正常工作 在我看来,这与其说是android的失败,不如说是php的失败 你的
Toast.makeText(SearchActivity.this,response,Toast.LENGTH_LONG).show();
打印内容?如果没有错误,请尝试放置一些日志以确保从对话框中获取的内容不是空的如果没有错误,请尝试放置一些日志以确保从对话框中获取的内容不是空的是,它显示未定义的索引id\u编号和未定义的索引原因。我假设变量可能没有被发布到APIMAN中。当您使用它时,postman是否显示了一些东西,在您的数据库中添加了一些东西?是的,它显示了未定义的索引id_编号和未定义的索引原因。我假设这些变量可能没有被发布到APIMAN中。当您使用它时,postman是否会在您的数据库中显示一些内容,添加一些内容?