得到太多类型“在这条线上的多个标记”的错误

时间:2013-06-03 10:03:11

标签: android

这是代码:

public void onClick(DialogInterface dialog, int whichButton)
    {
        Toast.makeText(getBaseContext(), "Cancel clicked", Toast.LENGTH_SHORT);

    }
}
builder.setMultiChoiceItems(items , itemsChecked,
        new DialogInterface.OnMultiChoiceClickListener()
{
    public void onClick(DialogInterface dialog, int which, boolean isChecked)
    {
        Toast.makeText(getBaseContext(), items[which]+ (isChecked ? "checked!" : "unchecked!"),
                Toast.LENGTH_SHORT).show();

    }
});  

虽然代码对我来说是正确的,但我得到了许多花括号相关的错误..请帮助!!

4 个答案:

答案 0 :(得分:0)

public void onClick(DialogInterface dialog, int whichButton)
    {
        Toast.makeText(getBaseContext(), "Cancel clicked", Toast.LENGTH_SHORT);



builder.setMultiChoiceItems(items , itemsChecked,
        new DialogInterface.OnMultiChoiceClickListener()
{
    public void onClick(DialogInterface dialog, int which, boolean isChecked)
    {
        Toast.makeText(getBaseContext(), items[which]+ (isChecked ? "checked!" : "unchecked!"),
                Toast.LENGTH_SHORT).show();

    }
});
}

答案 1 :(得分:0)

用这个替换你的代码......

builder.setMultiChoiceItems(items , itemsChecked, new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
    Toast.makeText(getBaseContext(), items[which]+ (isChecked ? "checked!" : "unchecked!"), Toast.LENGTH_SHORT).show();
}
});

答案 2 :(得分:0)

你只需要在最后一行添加一个简单的括号')'。

});

见下文

builder.setMultiChoiceItems(items , itemsChecked,
        new DialogInterface.OnMultiChoiceClickListener()
{
    public void onClick(DialogInterface dialog, int which, boolean isChecked)
    {
        Toast.makeText(getBaseContext(), items[which]+ (isChecked ? "checked!" : "unchecked!"),
                Toast.LENGTH_SHORT).show();

    }
});

答案 3 :(得分:0)

public void onClick(DialogInterface dialog, int whichButton)
    {
        Toast.makeText(getBaseContext(), "Cancel clicked", Toast.LENGTH_SHORT).show();<//here you missed to call show method

    }
}

builder.setMultiChoiceItems(items , itemsChecked,
        new DialogInterface.OnMultiChoiceClickListener()
{
    public void onClick(DialogInterface dialog, int which, boolean isChecked)
    {
        Toast.makeText(getBaseContext(), items[which]+ (isChecked ? "checked!" : "unchecked!"),
                Toast.LENGTH_SHORT).show();

    }
});//here to add ')' before semicolon