我将在我的应用程序中使用一个toast来进行测试。我刚接触Android环境,对toast不是很熟悉。我知道标准的toast如下:Toast.makeText(context, text, duration).show();
。然而,我想要在“text”部分应用一个变量,而不是一个文本字符串。
这是我写的代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_screen_next);
Button send = (Button) findViewById(R.id.bSend);//Import button1 (Send)
send.setOnClickListener(new OnClickListener() {//Set an onClickListener for the button to work
public void onClick(View v) {
Toast.makeText(getApplicationContext(), cText, Toast.LENGTH_LONG).show();
}//end method
});//End Send
}//End onCreate
cText
是在类中的另一个方法中使用的变量。您有什么建议,我如何让toast包含cText
的内容?提前致谢。
cText
的类型是什么?它是否局限于其他方法? - jlordo