简体   繁体   English

捕获不执行吐司

[英]Catch doesn't execute Toast

I want to show a message to the users when they click "Bintro" button and the EditTexts were empty. 当用户单击“ Bintro”按钮并且EditTexts为空时,我想向用户显示一条消息。

I have the next code: 我有下一个代码:

Bintro.setOnClickListener(new View.OnClickListener() {
        String eva;
        double por, not;

        @Override
        public void onClick(View v){

            try{
                eva = edEva.getText().toString();
                por = Double.parseDouble(edPor.getText().toString());
                not = Double.parseDouble(edNot.getText().toString());
            }
            catch (Exception e){
                Toast.makeText(getApplicationContext(), "Faltan datos por introducir", Toast.LENGTH_LONG);
                return;
            }

//The code continues down here but it's irrelevant to solve the question.

My problem is that when I click the button and there is no EditText filled, the 'catch' doesn't execute the Toast message but, however, it returns the app progress out of the onClick method. 我的问题是,当我单击按钮并且没有填充EditText时,“ catch”不执行Toast消息,但是,它从onClick方法返回了应用进度。 When they are filled, the app executes the code below 'catch' perfectly. 填充完毕后,应用程序将完美执行“ catch”下面的代码。

Hope you can help with my code or with another way to do it. 希望您能为我的代码或其他方式提供帮助。 Thanks. 谢谢。

you're not showing your toast. 你没有表现出敬酒。 add: 加:

    Toast.makeText(getApplicationContext(), "Faltan datos por introducir", Toast.LENGTH_LONG).show();

Try 尝试

  catch (Exception e){
            Toast.makeText(v.getContext(), "Faltan datos por introducir", Toast.LENGTH_LONG).show();
            return;
        }

您未在以下位置使用:

Toast.makeText(class_name.this, "Message_name",Toast.LENGTH_LONG).show();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM