调用最终的可编辑内容以在 toast 中使用

发布于 2024-10-13 17:39:17 字数 2047 浏览 7 评论 0原文

我不确定如何处理这个问题。 我已经采取了这里另一个人给出的一些指导方针,现在已经到了当我按下按钮(显示器)时它崩溃的地步 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘亓 2024-10-20 17:39:17
Toast.makeText(Change.this, "First Last \n Street Line 1 \n Line 2 \n City, State Zip", Toast.LENGTH_SHORT).show();

通过使用上面的吐司,我们可以以多行显示输出。在上面的语句中,我在那个地方使用静态文本,你放置所需的字段,例如

Toast.makeText(Change.this, firstField.getText().toString()+"\n"+ lastField.getText().toString()+"\n"+ City.getText().toString(), Toast.LENGTH_SHORT).show();
Toast.makeText(Change.this, "First Last \n Street Line 1 \n Line 2 \n City, State Zip", Toast.LENGTH_SHORT).show();

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

Toast.makeText(Change.this, firstField.getText().toString()+"\n"+ lastField.getText().toString()+"\n"+ City.getText().toString(), Toast.LENGTH_SHORT).show();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文