如何在过滤方法中烘烤消息?

时间:2018-10-30 13:24:39

标签: android android-toast

接口:-

enter image description here

我想发表祝酒词,如果用户未选择任何主题,它将祝酒词“请选择主题”。没有错误,问题是我不知道在需要时将代码放在哪里显示吐司消息。

编码:-

@Override
public void onClick(View v) {
    final MediaPlayer mediaPlayer = MediaPlayer.create(FilterTuitionCentreActivity.this, R.raw.soundeffect1);

    if (v == filterButton) {
        mediaPlayer.start();
        filterBtnFlag = true;
        if(spLocation.getSelectedItem() == null){
            return;
        }

        /*if(!(spSubject.getSelectedItem().toString().equalsIgnoreCase("Subject")
                || spSubject.getSelectedItem().toString().equalsIgnoreCase("Choose Subject"))){
            Toast.makeText(FilterTuitionCentreActivity.this, "Please choose subject.", Toast.LENGTH_SHORT).show();
        }*/

        else {
            loadFilteredInstitutesList("Advertisement");
        }

    }
}

1 个答案:

答案 0 :(得分:0)

您需要采取行动,提高验证逻辑,如果验证失败,则无需进一步操作即可返回。

            @Override
              public void onClick(View v) {

      //add your spinner validity checking here     

        if(!(spSubject.getSelectedItem().toString().equalsIgnoreCase("Subject")
                                || 

spSubject.getSelectedItem().toString().equalsIgnoreCase("Choose Subject"))){
                        Toast.makeText(FilterTuitionCentreActivity.this, "Please choose subject.", Toast.LENGTH_SHORT).show();
               return;
                    }

                final MediaPlayer mediaPlayer = MediaPlayer.create(FilterTuitionCentreActivity.

        this, R.raw.soundeffect1);

                if (v == filterButton) {
                    mediaPlayer.start();
                    filterBtnFlag = true;
                    if(spLocation.getSelectedItem() == null){
                        return;
                    }


                 loadFilteredInstitutesList("Advertisement");


                }
            }