Android:无法解析符号setDuration和Toast.LENGTH_LONG

时间:2016-06-07 14:17:31

标签: java android text toast duration

将持续时间和文字设置为吐司时遇到问题。我在我的三项活动中敬酒,出于某种原因,它只发生在其中一项活动中。我也尝试过重建和清理项目,但是没有用。 这是代码:

public class EconFragment extends AppCompatActivity {

private EditText userInputText = (EditText) findViewById(R.id.userInputText);
String userInput = userInputText.getText().toString();

final Toast firstToast = new Toast(this);
final Toast secondToast = new Toast(this);

firstToast.setDuration(Toast.LENGTH_LONG);
firstToast.setText("Correct");
secondToast.setDuration(Toast.LENGTH_LONG);
secondToast.setText("Incorrect");

private TextView definitionTextView = (TextView) findViewById(R.id.definitonTextView);
String definitionText = definitionTextView.getText().toString();

int value = (int )(Math.random() * 3 );
}

1 个答案:

答案 0 :(得分:2)

这是我通常使用的代码。它比你正在使用的更简洁。

Toast.makeText(this,“INSERT TEXT HERE”,Toast.LENGTH_LONG).show();