如何在警报对话框中扩充布局并通过适配器将数据从输入发送到 rest Api
How to inflater layout in Alert Dialog box and send data from input to restApi through adapter
在 bindViewHolder 适配器上的 AlertDialog 框中展开布局时出现问题,在声明和创建 LayoutInflater 对象时出现错误。
我搜索了很多,但找不到单一的解决方案,实际上,我正在膨胀布局,它将包含来自 RestAPI 的输入并将数据作为参数发送到 RestAPI。请帮我解决错误。
如果我得到了布局,那么我应该在哪里进行 post 操作(在适配器或主 class 中?请帮助我使用 StringRequest 和 URL 并排球网络)
适配器代码:
holder.editbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(v.getContext(),"edit"+listClient.getCustomername(),Toast.LENGTH_SHORT).show();
AlertDialog.Builder builder=new AlertDialog.Builder(v.getRootView().getContext());
LayoutInflater inflater =v.getLayoutInflater;//Getting Errorrrr
builder.setView(inflater.inflate(R.layout.edit_dialog, null));
builder.setTitle("Client Status update")
.setMessage("client name:"+listClient.getCustomername())
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.i("Result","Success");
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.i("Result","UnSuccess");
}
})
.show();
}
//main中的status方法class
public无效状态(){
final String status=;//how to get the string from the adapter dialog input??
StringRequest stringRequest =new StringRequest(Request.Method.POST,
URLs.URL_status_change,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
//Toast.makeText(getApplicationContext(),response, Toast.LENGTH_LONG).show();
try{
JSONObject obj = new JSONObject(response);
if (!obj.getBoolean("error")) {
Toast.makeText(getApplicationContext(), obj.getString("message"), Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getApplicationContext(), obj.getString("message"), Toast.LENGTH_SHORT).show();
}
}catch (JSONException e){
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
Toast.makeText(Track_issues_client.this,volleyError.toString(),Toast.LENGTH_LONG).show();
}
}){
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("status",status);
return params;
}
};
// Instantiate the RequestQueue.
RequestQueue requestQueue= Volley.newRequestQueue(this);
// Add the request to the RequestQueue.
requestQueue.add(stringRequest);
}
适配器代码:
@Override
public void onClick(View v) {
Toast.makeText(v.getContext(),"edit"+listClient.getCustomername(),Toast.LENGTH_SHORT).show();
AlertDialog.Builder builder=new AlertDialog.Builder(v.getRootView().getContext());
View mView = LayoutInflater.from(v.getRootView().getContext()).inflate(R.layout.edit_dialog, null);
// String a =status.setText(listClient.getStatus().toString());
builder.setView(mView);
builder.setTitle("Client Status update")
.setMessage("client name:"+listClient.getCustomername())
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
c.status();
Log.i("Result","Success");
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.i("Result","UnSuccess");
}
})
.show();
}
检查这个解决方案。
holder.editbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(v.getContext(),"edit"+listClient.getCustomername(),Toast.LENGTH_SHORT).show();
AlertDialog.Builder builder=new AlertDialog.Builder(v.getRootView().getContext());
View mView = LayoutInflater.from(v.getRootView().getContext()).inflate(R.layout.edit_dialog, null);
builder.setView(mView);
builder.setTitle("Client Status update")
.setMessage("client name:"+listClient.getCustomername())
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.i("Result","Success");
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.i("Result","UnSuccess");
}
})
.show();
}
在 bindViewHolder 适配器上的 AlertDialog 框中展开布局时出现问题,在声明和创建 LayoutInflater 对象时出现错误。
我搜索了很多,但找不到单一的解决方案,实际上,我正在膨胀布局,它将包含来自 RestAPI 的输入并将数据作为参数发送到 RestAPI。请帮我解决错误。
如果我得到了布局,那么我应该在哪里进行 post 操作(在适配器或主 class 中?请帮助我使用 StringRequest 和 URL 并排球网络)
适配器代码:
holder.editbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(v.getContext(),"edit"+listClient.getCustomername(),Toast.LENGTH_SHORT).show();
AlertDialog.Builder builder=new AlertDialog.Builder(v.getRootView().getContext());
LayoutInflater inflater =v.getLayoutInflater;//Getting Errorrrr
builder.setView(inflater.inflate(R.layout.edit_dialog, null));
builder.setTitle("Client Status update")
.setMessage("client name:"+listClient.getCustomername())
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.i("Result","Success");
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.i("Result","UnSuccess");
}
})
.show();
}
//main中的status方法class public无效状态(){
final String status=;//how to get the string from the adapter dialog input??
StringRequest stringRequest =new StringRequest(Request.Method.POST,
URLs.URL_status_change,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
//Toast.makeText(getApplicationContext(),response, Toast.LENGTH_LONG).show();
try{
JSONObject obj = new JSONObject(response);
if (!obj.getBoolean("error")) {
Toast.makeText(getApplicationContext(), obj.getString("message"), Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getApplicationContext(), obj.getString("message"), Toast.LENGTH_SHORT).show();
}
}catch (JSONException e){
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
Toast.makeText(Track_issues_client.this,volleyError.toString(),Toast.LENGTH_LONG).show();
}
}){
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("status",status);
return params;
}
};
// Instantiate the RequestQueue.
RequestQueue requestQueue= Volley.newRequestQueue(this);
// Add the request to the RequestQueue.
requestQueue.add(stringRequest);
}
适配器代码:
@Override
public void onClick(View v) {
Toast.makeText(v.getContext(),"edit"+listClient.getCustomername(),Toast.LENGTH_SHORT).show();
AlertDialog.Builder builder=new AlertDialog.Builder(v.getRootView().getContext());
View mView = LayoutInflater.from(v.getRootView().getContext()).inflate(R.layout.edit_dialog, null);
// String a =status.setText(listClient.getStatus().toString());
builder.setView(mView);
builder.setTitle("Client Status update")
.setMessage("client name:"+listClient.getCustomername())
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
c.status();
Log.i("Result","Success");
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.i("Result","UnSuccess");
}
})
.show();
}
检查这个解决方案。
holder.editbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(v.getContext(),"edit"+listClient.getCustomername(),Toast.LENGTH_SHORT).show();
AlertDialog.Builder builder=new AlertDialog.Builder(v.getRootView().getContext());
View mView = LayoutInflater.from(v.getRootView().getContext()).inflate(R.layout.edit_dialog, null);
builder.setView(mView);
builder.setTitle("Client Status update")
.setMessage("client name:"+listClient.getCustomername())
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.i("Result","Success");
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.i("Result","UnSuccess");
}
})
.show();
}