如何解决Android - 布局在显示警报对话框时重置 | Alertdialog 重新设置自定义列表视图的视图
我有一个带有按钮的自定义列表视图。我在其上设置了一个 OnLickListener 并在我的活动中实现了该接口。我必须显示一个 https://{TenatName}.onmicrosoft.com/api/Read.All
,它在 edittext 中输入。单击确定后,我调用另一种方法来禁用列表视图中的按钮。 不幸的是,这不起作用。按钮会在一秒钟内重置为原始状态。
注意:这只会在我显示 AlertDialog 时发生,否则它工作正常。
我的适配器代码:
AlertDialog
我的点击:
public View getView(int position,@Nullable View convertView,@NonNull ViewGroup parent) {
View view = LayoutInflater.from(context).inflate(R.layout.list_doctors,parent,false);
ImageView image = view.findViewById(R.id.image);
TextView name = view.findViewById(R.id.names);
TextView specification = view.findViewById(R.id.specification);
TextView status = view.findViewById(R.id.status);
Button appoint = view.findViewById(R.id.appoint);
Doctor doctor = doctors.get(position);
name.setText(doctor.getName());
status.setText(doctor.getStatus());
specification.setText(doctor.getSpecification());
image.setImageResource(doctor.getImage());
if (listener != null){
appoint.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onClick((Button) v,position,doctor.getName());
}
});
}
return view;
}
我的 askTag() 或 AlertDialog:
adapter.setOnItemClickListener(new OnItemClick() {
@Override
public void onClick(Button view,int position,String name) {
askTag(); // ---> This is causing the problem
if (isInternetOn() && appointments != null) {
Calendar calendar = Calendar.getInstance();
String date = calendar.get(Calendar.DAY_OF_MONTH) + "/" + calendar.get(Calendar.MONTH) + "/" + calendar.get(Calendar.YEAR);
appointments.add(new Appointment(name,tag,date));
appoint(view);
} else
Toast.makeText(DoctorActivity.this,"Please check your internet.",Toast.LENGTH_LONG).show();
}
});
}
private void appoint(Button view) {
database.child(ID).setValue(appointments,new DatabaseReference.CompletionListener() {
@Override
public void onComplete(@Nullable DatabaseError error,@NonNull @NotNull DatabaseReference ref) {
if (error == null){
view.setText("Appointed"); // -----> Doesn't work if I display that alertdialog
view.setEnabled(false); // -----> Doesn't work if I display that alertdialog
Toast.makeText(DoctorActivity.this,"Your appointment is registered. Check appointment history",Toast.LENGTH_LONG).show();
} else {
Toast.makeText(DoctorActivity.this,"Something went wrong",Toast.LENGTH_SHORT).show();
error.toException().printStackTrace();
}
}
});
}
发生这种情况的任何原因?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。