Reputation: 17
I am beginner in android development,The problem which i m facing is that once i Click to Edit Button which is on CardView is Not Displaying Alert Dialog Box where i will update the details related to that cardview.
I tried making that Edit Button functionable by placing Toast to check if it is working and hence it worked,i even created a separate Dialog Box in main activity and just to see if it is working and it works but when i call the same in adapter using object of that class it gives error.
I am Retrieving Data from Database converting into Json and this data is Displayed in Cardview in recyclerview using StringRequest and volley for network
Expected output: Onclick of EditButton on Cardview in Recycler view it should display me an Alert or dialog box which will Consist Name of the person that is the Card which i clicked and input in dialog and then submit.
Someone save my time coz i have invested lots of time trying..Thank u in advance
Adapter code:
@Override
public void onBindViewHolder(MyClientTrackAdapter.ViewHolder holder, int position) {
// Find out the data, based on this view holder's position
final ListClientTrackIssue listClient = listClients.get(position);
holder.textViewCustomer.setText(listClient.getCustomername());
holder.textViewcurdate.setText(listClient.getCurdate());
holder.textViewcurtime.setText(listClient.getCurtime());
holder.textViewtargetdate.setText(listClient.getTargetdate());
holder.textViewtargettime.setText(listClient.getTargettime());
holder.textViewquery.setText(listClient.getQuery());
holder.textViewaddress.setText(listClient.getAddress());
holder.textViewassigned.setText(listClient.getAssignedperson());
holder.textViewcomment.setText(listClient.getComment());
holder.textViewstatus.setText(listClient.getStatus());
holder.editbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(v.getContext(),"edit"+listClient.getCustomername(),Toast.LENGTH_SHORT).show();
new AlertDialog.Builder(context)
.setMessage("client"+listClient.getCustomername())
.setTitle("Client Status update")
.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","Success");
}
})
.show();
}
});
}
@Override
public int getItemCount() {
return listClients.size();
}
class ViewHolder extends RecyclerView.ViewHolder {
Button editbutton;
TextView textViewCustomer,textViewcurdate,textViewcurtime,textViewtargetdate,textViewtargettime,
textViewquery,textViewaddress,textViewassigned,textViewcomment,textViewstatus;
public ListCustomer listCustomer;
public ViewHolder(View itemView) {
super(itemView);
textViewCustomer=itemView.findViewById(R.id.textViewCustomer);
textViewcurdate=itemView.findViewById(R.id.textViewcurdate);
textViewcurtime=itemView.findViewById(R.id.textViewcurtime);
textViewtargetdate=itemView.findViewById(R.id.textViewtargetdate);
textViewtargettime=itemView.findViewById(R.id.textViewtargettime);
textViewquery=itemView.findViewById(R.id.textViewquery);
textViewaddress=itemView.findViewById(R.id.textViewaddress);
textViewassigned=itemView.findViewById(R.id.textViewassigned);
textViewcomment=itemView.findViewById(R.id.textViewcomment);
textViewstatus=itemView.findViewById(R.id.textViewstatus);
this.editbutton=itemView.findViewById(R.id.editbtn);
Main class code:
public void showChangeLangDialog(){
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
LayoutInflater inflater = this.getLayoutInflater();
final View dialogView = inflater.inflate(R.layout.edit_dialog, null);
dialogBuilder.setView(dialogView);
//final EditText edt = (EditText) dialogView.findViewById(R.id.edit1);
dialogBuilder.setTitle("Update Client Status");
dialogBuilder.setPositiveButton("Update", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//do something with edt.getText().toString();
}
});
dialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//pass
}
});
AlertDialog b = dialogBuilder.create();
b.show();
}
Upvotes: 0
Views: 1918
Reputation: 131
i am new in andriod developing but i created custom dialog in adapter this cod here:
holder.viewDesign.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Dialog dialog = new Dialog(mCtx);
dialog.setContentView(R.layout.show_standerd_product);
dialog.setTitle("Position" + position);
dialog.setCancelable(true);
ImageView d_image = dialog.findViewById(R.id.dialog_design_image);
TextView d_type = dialog.findViewById(R.id.dialog_design_type);
TextView d_name = dialog.findViewById(R.id.dialog_design_name);
TextView d_cost = dialog.findViewById(R.id.dialog_design_cost);
d_type.setText(standerdProduct.getType());
d_name.setText(standerdProduct.getName());
d_cost.setText("Cost :" + String.valueOf(standerdProduct.getAmount()));
Glide.with(mCtx)
.load("http://yourSystemIpAddressforXAMP/darzee/" + standerdProduct.getImage())
.into(d_image);
dialog.show();
}
});
Upvotes: 1
Reputation: 131
holder.editbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(v.getContext(),"edit"+listClient.getCustomername(),Toast.LENGTH_SHORT).show();
new AlertDialog.Builder(v.getRootView().getContext())
.setMessage("client"+listClient.getCustomername())
.setTitle("Client Status update")
.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","Success");
}
})
.show();
}
});
Upvotes: 2
Reputation: 273
just create interface in adapter class and
Interface
public interface Clicked{
void Buttonclick(View v,int position);
}
Clicked clicked;
button click
yourbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int pos = (int) v.getTag();
if (clicked != null) {
clicked.Buttonclick(v, pos);
}
}
});
Adapter adapter=new Adapter(yourlist, new Adapter.Clicked() {
@Override
public void click(View view, int position) {
if(view.getId()==your view id) {
showdialog();
}
}
});
this way you can get click of button in cardview in your activity/fragment and you can show dialog
Upvotes: 1