调用最终的Editables用于吐司

时间:2011-01-20 04:14:53

标签: android onclick toast android-edittext

我不确定如何处理这个问题。 我已经采取了另一个人在这里给出的一些指导,现在当我按下按钮(显示器)时它已经到了崩溃的程度 http://i.stack.imgur.com/C8WgN.png

我希望能够在按下按钮时发布Toast通知,然后在几秒钟之后让它消失 此外,有没有办法将它创建到仍会创建Toast通知的位置,尽管某些信息(如line2)是空的?

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();
     } 
    });
 }
    }

我希望吐司的布局是多行的,看起来像邮政地址

第一个最后一个 街道1号 第2行 城市,州邮编

1 个答案:

答案 0 :(得分:2)

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

通过使用上面的toast,我们可以在多行显示输出。在上面的语句中,我在那个地方使用静态文本你把所需的fieds像

Toast.makeText(Change.this, firstField.getText().toString()+"\n"+ lastField.getText().toString()+"\n"+ City.getText().toString(), Toast.LENGTH_SHORT).show();