gpt4 book ai didi

java - 单击 Cardview 中的按钮打开对话框

转载 作者:行者123 更新时间:2023-12-02 11:41:07 25 4
gpt4 key购买 nike

我是android开发的初学者,我面临的问题是,一旦我单击CardView上的编辑按钮,就不会显示警报对话框,我将在其中更新与该cardview相关的详细信息。

我尝试通过放置 Toast 来检查它是否正常工作,从而使该编辑按钮功能正常,我什至在主 Activity 中创建了一个单独的对话框,只是为了查看它是否正常工作并且它有效,但是当我调用在使用该类对象的适配器中相同,它会给出错误。

我正在从数据库中检索数据并将其转换为 Json,并且该数据使用 StringRequest 和 volley 进行网络显示在 recyclerview 的 Cardview 中

预期输出:在 Recycler View 中单击 Cardview 上的 EditButton 时,它应该向我显示一个警报或对话框,其中包含我单击并在对话框中输入的卡片的人员姓名,然后提交。

有人节省了我的时间,因为我投入了大量时间尝试..提前谢谢你

适配器代码:

@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);

主类代码:

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();
}

最佳答案

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();

}

});

关于java - 单击 Cardview 中的按钮打开对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48540065/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com