对话框关闭在适配器内不起作用

我有一个模式(对话框),里面有编辑文本和发送按钮,我想做的只是在单击按钮时发送编辑文本内的内容,问题是,发送内容正在工作,但是当我打电话时mydialog.dismiss();它不起作用。它使用另一个类的实例来调用方法改造,在“完成”和“未完成”按钮内,我有一个“enviar”(发送)按钮,这是我试图关闭模式的按钮。


这是适配器代码:


public TasksAdapter(@NonNull Context context, @SuppressLint("SupportAnnotationUsage") @LayoutRes ArrayList<Tasks> list){

    super(context, 0, list);

    sContext = context;

    taskData = list;

}


@NonNull

@Override

public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent){


    View listItem = convertView;

    if(listItem == null)

        listItem = LayoutInflater.from(sContext).inflate(R.layout.item_tasks, parent,false);


    final Tasks presenteTask = taskData.get(position);


    TextView taskTitle = (TextView) listItem.findViewById(R.id.tasksTitle);

    taskTitle.setText(presenteTask.getTitle());


    EditText taskColor = (EditText) listItem.findViewById(R.id.taskColor);

    if(presenteTask.getHexaColor().isEmpty()){

        HexaColor = "#FFFFFF";

    }

    else{

        HexaColor = presenteTask.getHexaColor();

        taskColor.setBackgroundColor(Color.parseColor(HexaColor));

    }


    TextView taskTime = (TextView) listItem.findViewById(R.id.taskTime);

    taskTime.setText(presenteTask.getTimeStart().toString().substring(0,5));


    tasksModal = new Dialog(sContext);

    tasksModal.setCancelable(false);

    tasksModal.setContentView(R.layout.modal_tasksdone);

    tasksModal.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

    final EditText comentarios = (EditText) tasksModal.findViewById(R.id.edtComentario);

    final Calendario calendario = new Calendario();


    Button done = (Button) listItem.findViewById(R.id.tasksDone);

    done.setOnClickListener(new View.OnClickListener() {

        @Override

        public void onClick(View view) {

            yorn = true;

            tarefaId = presenteTask.getTaskId();

            data = presenteTask.getDataTask();

            hora = String.valueOf(presenteTask.getTimeStart());



阿波罗的战车
浏览 95回答 1
1回答

暮色呼如

首先,您必须使对话框不可取消,以便外部单击不会使用以下命令将其关闭tasksModal.setCancelable(false);其次,无需重复代码来在done/undone按钮单击内创建对话框。因此,删除它并将其移至TasksAdapter构造函数。第三,您不会在单击按钮时关闭对话框done。所以,添加这个tasksModal.dismiss();检查并尝试使用以下代码:EditText comentarios;Calendario calendario;public TasksAdapter(@NonNull Context context, @SuppressLint("SupportAnnotationUsage") @LayoutRes ArrayList<Tasks> list){&nbsp; &nbsp; super(context, 0, list);&nbsp; &nbsp; sContext = context;&nbsp; &nbsp; taskData = list;&nbsp; &nbsp; tasksModal = new Dialog(sContext);&nbsp; &nbsp; tasksModal.setCancelable(false); //make it un cancelable&nbsp; &nbsp; tasksModal.setContentView(R.layout.modal_tasksdone);&nbsp; &nbsp; tasksModal.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));&nbsp; &nbsp; comentarios = (EditText) tasksModal.findViewById(R.id.edtComentario);&nbsp; &nbsp; calendario = new Calendario();}-------------------------------------------------------------Button done = (Button) listItem.findViewById(R.id.tasksDone);done.setOnClickListener(new View.OnClickListener() {&nbsp; &nbsp; @Override&nbsp; &nbsp; public void onClick(View view) {&nbsp; &nbsp; &nbsp; &nbsp; comentarios.setText("");&nbsp; &nbsp; &nbsp; &nbsp; yorn = true;&nbsp; &nbsp; &nbsp; &nbsp; tarefaId = presenteTask.getTaskId();&nbsp; &nbsp; &nbsp; &nbsp; data = presenteTask.getDataTask();&nbsp; &nbsp; &nbsp; &nbsp; hora = String.valueOf(presenteTask.getTimeStart());&nbsp; &nbsp; &nbsp; &nbsp; tasksModal.findViewById(R.id.btnSend).setOnClickListener(new View.OnClickListener() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Override&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void onClick(View view) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; comentario = comentarios.getEditableText().toString();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(!comentario.equals("")){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tasksModal.dismiss(); //dismiss here&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; calendario.retrofitDoneTasks(tarefaId, comentario, data, hora, yorn, tarefaRealizadaId);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Toast.makeText(sContext,"Por favor digite um comentário.", Toast.LENGTH_SHORT).show();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; tasksModal.show();&nbsp; &nbsp; }});Button notDone = (Button) listItem.findViewById(R.id.tasksNotDone);notDone.setOnClickListener(new View.OnClickListener() {&nbsp; &nbsp; @Override&nbsp; &nbsp; public void onClick(View view) {&nbsp; &nbsp; &nbsp; &nbsp; comentarios.setText("");&nbsp; &nbsp; &nbsp; &nbsp; yorn = false;&nbsp; &nbsp; &nbsp; &nbsp; tarefaId = presenteTask.getTaskId();&nbsp; &nbsp; &nbsp; &nbsp; data = presenteTask.getDataTask();&nbsp; &nbsp; &nbsp; &nbsp; hora = String.valueOf(presenteTask.getTimeStart());&nbsp; &nbsp; &nbsp; &nbsp; tasksModal.findViewById(R.id.btnSend).setOnClickListener(new View.OnClickListener() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Override&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void onClick(View view) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; comentario = comentarios.getEditableText().toString();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(comentario.equals("")){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Toast.makeText(sContext,"Por favor digite um comentário.", Toast.LENGTH_SHORT).show();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tasksModal.dismiss();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; calendario.retrofitDoneTasks(tarefaId, comentario, data, hora, yorn, tarefaRealizadaId);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; tasksModal.show();&nbsp; &nbsp; }});
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java