调用最终的可编辑内容以在 toast 中使用
我不确定如何处理这个问题。 我已经采取了这里另一个人给出的一些指导方针,现在已经到了当我按下按钮(显示器)时它崩溃的地步 https://i.sstatic.net/C8WgN.png
我希望能够发布按下按钮时发出 toast 通知,然后让它在几秒钟后消失 另外,有没有办法做到这一点,尽管某些信息(如第 2 行)是空的,但它仍然会创建一个 toast 通知?
basic.java:
public class Basic extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.basic);
Spinner spinner = (Spinner) findViewById(R.id.Spinner01);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.state_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
final Button display = (Button) findViewById(R.id.Button01);
display.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
EditText firstField = (EditText) findViewById(R.id.First);
EditText lastField = (EditText) findViewById(R.id.Last);
EditText line1Field = (EditText) findViewById(R.id.Line1);
EditText line2Field = (EditText) findViewById(R.id.Line2);
EditText cityField = (EditText) findViewById(R.id.City);
EditText stateField = (EditText) findViewById(R.id.Spinner01);
EditText zipField = (EditText) findViewById(R.id.Zip);
//EditText phoneField = (EditText) findViewById(R.id.Telephone);
final Editable firstName = firstField.getText();
final Editable lastName = lastField.getText();
final Editable lineOne = line1Field.getText();
final Editable lineTwo = line2Field.getText();
final Editable city = cityField.getText();
final Editable state = stateField.getText();
final Editable zip = zipField.getText();
//final Editable phoneNumber = phoneField.getText();
Toast toDisplay = Toast.makeText(null, firstName, 10);
toDisplay.show();
}
});
}
}
我希望吐司的布局是多行的,并且看起来像邮政地址
First Last
街道1号线
2号线
城市、州邮政编码
I am unsure as to how to approach this.
I have taken some guidelines given by another person on here and have now gotten to the point of it crashing when I push the button (the monitor)
https://i.sstatic.net/C8WgN.png
I want to be able to post a toast notification when the button is pushed, and then have it go away after a few seconds
Also, is there a way to do it to where it will still create a toast notification although some of the info (like line2) is empty?
basic.java:
public class Basic extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.basic);
Spinner spinner = (Spinner) findViewById(R.id.Spinner01);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.state_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
final Button display = (Button) findViewById(R.id.Button01);
display.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
EditText firstField = (EditText) findViewById(R.id.First);
EditText lastField = (EditText) findViewById(R.id.Last);
EditText line1Field = (EditText) findViewById(R.id.Line1);
EditText line2Field = (EditText) findViewById(R.id.Line2);
EditText cityField = (EditText) findViewById(R.id.City);
EditText stateField = (EditText) findViewById(R.id.Spinner01);
EditText zipField = (EditText) findViewById(R.id.Zip);
//EditText phoneField = (EditText) findViewById(R.id.Telephone);
final Editable firstName = firstField.getText();
final Editable lastName = lastField.getText();
final Editable lineOne = line1Field.getText();
final Editable lineTwo = line2Field.getText();
final Editable city = cityField.getText();
final Editable state = stateField.getText();
final Editable zip = zipField.getText();
//final Editable phoneNumber = phoneField.getText();
Toast toDisplay = Toast.makeText(null, firstName, 10);
toDisplay.show();
}
});
}
}
I would like the layout of the toast to be multi-lined, and looking like a postal address
First Last
Street Line 1
Line 2
City, State Zip
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过使用上面的吐司,我们可以以多行显示输出。在上面的语句中,我在那个地方使用静态文本,你放置所需的字段,例如
By using above toast we can display the output in multilines.In above statement i am using static text in that place u put required fieds like