Android-Toast.maketext无效

时间:2013-08-22 02:49:54

标签: android checkbox toast

我在Android中全新。例如,我创建了一个复选框,即使在VirtualBox中,Toast.maketext也不能在eclipse中的AVD中工作。任何人都可以告诉我我的代码有什么问题。 提前谢谢。

cbxReading = (CheckBox) findViewById(R.id.cbxReading);
cbxReading.getOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
    // TODO Auto-generated method stub
    if (isChecked) {
        if (hobbies.contains("Reading")) {
            hobbies.add("Reading");
            Toast.makeText(ctx, "Added Reading",
            Toast.LENGTH_SHORT).show();
        }
        } else {
            if (hobbies.contains("Reading")) {
                hobbies.remove("Reading");
               Toast.makeText(ctx, "Removed Reading",
                Toast.LENGTH_SHORT).show();
            }
        }
    }
});

2 个答案:

答案 0 :(得分:0)

试试这个

 public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
    // TODO Auto-generated method stub
     Toast.makeText(ctx, "Here!",
                Toast.LENGTH_SHORT).show();
    if (isChecked) {
        if (hobbies.contains("Reading")) {
            hobbies.add("Reading");
            Toast.makeText(ctx, "Added Reading",
            Toast.LENGTH_SHORT).show();
        }
        } else {
            if (hobbies.contains("Reading")) {
                hobbies.remove("Reading");
               Toast.makeText(ctx, "Removed Reading",
                Toast.LENGTH_SHORT).show();
            }
        }
    }
});

答案 1 :(得分:0)

而不是getOnCheckedChangeListener使用setOnCheckedChangeListener