我从数据库获得了一行,我使用textview来显示它们。 但我有一个按钮,它给出了一个字符串。当它被点击时,我希望将这些数据发布到现有的同一行。
public class RecyclerViewAdapter extends
RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder>
{
Context context;
int attempt=1,attempt1=2;
public static final String decline="0";
public static final String KEY_DECLINE = "decline";
public static final String accept="1";
public static final String KEY_ACCEPT = "accept";
List<GetDataAdapter> getDataAdapter;
public RecyclerViewAdapter(List<GetDataAdapter> getDataAdapter, Second context){
super();
this.getDataAdapter = getDataAdapter;
this.context = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.container_customer, parent, false);
ViewHolder viewHolder = new ViewHolder(v);
return viewHolder;
}
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
final GetDataAdapter getDataAdapter1 = getDataAdapter.get(position);
holder.NameTextView.setText("Name:"+getDataAdapter1.getName());
holder.IdTextView.setText("ID:"+getDataAdapter1.getId());
holder.PhoneNumberTextView.setText("Problem:"+getDataAdapter1.getPhone_number());
holder.SubjectTextView.setText("Phone:"+getDataAdapter1.getSubject());
holder.address.setText("Address"+getDataAdapter1.getAddress());
holder.accept.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(final View v) {
holder.details.setBackgroundColor(Color.GREEN);
holder.decline.setEnabled(false);
StringRequest stringRequest = new StringRequest(Request.Method.POST, Url.REGISTER_URL_ACCEPT,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(v.getContext(), response, Toast.LENGTH_LONG).show();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(v.getContext(), error.toString(), Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put(KEY_ACCEPT, accept);
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(context);
requestQueue.add(stringRequest);
}
}
);
holder.decline.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(final View v) {
holder.details.setBackgroundColor(Color.RED);
holder.accept.setEnabled(false);
StringRequest stringRequest = new StringRequest(Request.Method.POST, Url.REGISTER_URL_DECLINNE,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(v.getContext(), response, Toast.LENGTH_LONG).show();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(v.getContext(), error.toString(), Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put(KEY_DECLINE, decline);
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(context);
requestQueue.add(stringRequest);
}
}
);
}
@Override
public int getItemCount() {
return getDataAdapter.size();
}
class ViewHolder extends RecyclerView.ViewHolder{
public TextView IdTextView;
public TextView NameTextView;
public TextView PhoneNumberTextView;
public TextView SubjectTextView,address;
public Button accept,decline;
public LinearLayout details;
public ViewHolder(View itemView) {
super(itemView);
IdTextView = (TextView) itemView.findViewById(R.id.Id) ;
NameTextView = (TextView) itemView.findViewById(R.id.CustomerName) ;
PhoneNumberTextView = (TextView) itemView.findViewById(R.id.Typeofproblem) ;
SubjectTextView = (TextView) itemView.findViewById(R.id.Phoneno) ;
address=(TextView)itemView.findViewById(R.id.Address);
accept=(Button)itemView.findViewById(R.id.accept);
decline=(Button)itemView.findViewById(R.id.decline);
details=(LinearLayout)itemView.findViewById(R.id.details);
}
}
}
答案 0 :(得分:0)
您可以像这样将数据插入数据库
db.insert(TABLE_NAME, null, getMemberContentValues(object));
private ContentValues getMemberContentValues(Object object) {
if (object== null)
return null;
ContentValues contentValues = new ContentValues();
contentValues.put(Column_name1, object.getProperty1());
contentValues.put(Column_name2, object.getProperty2());
return contentValues;
}