Mega Code Archive

 
Categories / Android / UI
 

Set text for TextView

package app.test; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class Test extends Activity {   @Override   public void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     TextView tv = new TextView(this);     tv.setText("5! = " + factorial(5));     setContentView(tv);   }   public static long factorial(long n) {     if (n <= 0)       return 1;     else       return n * factorial(n - 1);   } }