z.k z.k - 1 year ago 143
Android Question

Display string variables in a Toast

I wanna display the information of 7

in a
so I put the edit texts information in 7 string variables but I don't know how.
Here is what I written:

public class MainActivity extends Activity {
EditText ed1;
EditText ed2;
EditText ed3;
EditText ed4;
EditText ed5;
EditText ed6;
EditText ed7;
Button btn;

protected void onCreate(Bundle savedInstanceState) {

private void showinfo() {
ed1= (EditText) findViewById(R.id.editText1);
ed2= (EditText) findViewById(R.id.editText2);
ed3= (EditText) findViewById(R.id.editText3);
ed4= (EditText) findViewById(R.id.editText4);
ed5= (EditText) findViewById(R.id.editText5);
ed6= (EditText) findViewById(R.id.editText6);
ed7= (EditText) findViewById(R.id.editText7);
btn= (Button) findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {

public void onClick(View arg0) {
// TODO Auto-generated method stub
String str1 = ed1.getText().toString();
String str2 = ed2.getText().toString();
String str3 = ed3.getText().toString();
String str4 = ed4.getText().toString();
String str5 = ed5.getText().toString();
String str6 = ed6.getText().toString();
String str7 = ed7.getText().toString();
Toast.makeText(getApplicationContext(), ,Toast.LENGTH_LONG).show();

How can I display all the string variables in

Answer Source

If you want to show all content of EditText in one Toast, then just use concatenation

String concatenatedText = str1 + str2 + str3 + ... 

or StringBuilder class:

StringBuilder sb = new StringBuilder();
String concatenatedText = sb.toString();

and simply pass the result as second argument, as below:

Toast toast = Toast.makeText(context, concatenatedText, duration);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download