Question

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) http://i.stack.imgur.com/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

Was it helpful?

Solution

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();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top