0

1) is there any easy way for screen output like in Pascal: write(A,'+',B,'=',C) ?

I tried :

void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.new_layout);
Toast.LENGTH_LONG).show();

    int A,B,C;
    A=4;
    B=8;
    C=A+B;
    String text = getString(A,"+",B,"=",C);

    TextView tv = (TextView) findViewById(R.id.textView1);               
    tv.setText(text);
    //Toast.makeText(this,text, Toast.LENGTH_LONG).show();
   }

but ít doesn't work. Every time I will get "...apliccation has stopped"

the best would be something like : tv.setText(A,"+",B,"=",C) //without stringing integers;

thanks for all your help.

4

2 回答 2

1

Concatenate the string and use setText afterwards:

tv.setText(A + "+" B + "=" + C);

For longer text, use a StringBuilder.

于 2013-07-06T13:48:38.380 回答
0

This is wrong getString(A,"+",B,"=",C)

you want

String text = A + "+" + B + "=" + C;


getString is used for retrieving package string resources

http://developer.android.com/reference/android/content/Context.html#getString(int)

于 2013-07-06T13:49:06.253 回答