我怎样才能在动作监听器中干杯

时间:2015-05-15 14:40:56

标签: java android toast

我正在尝试将Toast转换为按钮的ActionListener,但它不会出现。那么,有人可以帮助我吗? 这是班级的代码。

public class Numero extends ActionBarActivity {

    private String server;
    private String porta;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_combinazione);
        server = getIntent().getExtras().getString("server");
        porta = getIntent().getExtras().getString("porta");

        Button btnInvia=(Button)findViewById(R.id.button);
        btnInvia.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View arg0) {
                    // Azioni da fare per inviare combinazione
                        text= (EditText)findViewById(R.id.editText);
                        String num = text.getText().toString();

                        // Mi connetto al server
                        final AsyncTask<String, Void, Void> esegui = new ApriSocket().execute(server, porta, num);
                        if(num < 0) {
                            // Azione
                            Toast.makeText(this,"Numero minore di 0",Toast.LENGTH_LONG).show();
                        }
                    }
                }
        );
    }

2 个答案:

答案 0 :(得分:0)

改变这个:

Toast.makeText(this,"Numero minore di 0",Toast.LENGTH_LONG).show();

Toast.makeText(Numero.this,"Numero minore di 0",Toast.LENGTH_LONG).show();

答案 1 :(得分:0)

尝试:

Toast.makeText(getApplicationContext(), "Numero minore di 0" , 0).show();
相关问题