所选EditText的Toast:多个toast showen

时间:2013-04-21 04:21:25

标签: android focus android-edittext toast textwatcher

所以问题是,当我将焦点从EditText更改为另一个时,我会为所选的一个烘烤,但是我只是选择了一个EditText的Toast,我得到之前选择的那个,然后我得到了我选择的结果one。我不知道如何使用TextWatcher 以下是代码示例:

heure.setOnFocusChangeListener(new OnFocusChangeListener() {



            @Override
            public void onFocusChange(View arg0, boolean arg1) {
                datee.removeTextChangedListener(yourTextWatcher);
                Toast.makeText(RendezVousActivity.this,"heure", 5000).show();


            }
        });


        datee.setOnFocusChangeListener(new OnFocusChangeListener() {

            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                heure.removeTextChangedListener(yourTextWatcher);
                Toast.makeText(RendezVousActivity.this,"Date", 5000).show();

            }
        });

1 个答案:

答案 0 :(得分:1)

OnFocusChanged被调用两次:一次是在EditText聚焦时,一次是在它失去焦点时。

因此,当您单击EditText时,它会进行祝酒。然后当你点击另一个EditText时,第一个失去焦点,再次显示第一个吐司,然后第二个获得焦点,这显示你的第二个吐司。

如果您只想在选中时显示吐司,请尝试使用:

heure.setOnFocusChangeListener(new OnFocusChangeListener() {
    @Override
    public void onFocusChange(View arg0, boolean arg1) {
        datee.removeTextChangedListener(yourTextWatcher);
        if(v.isFocused()) {
            Toast.makeText(RendezVousActivity.this,"heure", 5000).show();
        }
    }
});

datee.setOnFocusChangeListener(new OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        heure.removeTextChangedListener(yourTextWatcher);
        if(v.isFocused()) {
            Toast.makeText(RendezVousActivity.this,"Date", 5000).show();
        }
    }
});