0

Im new at android developing. I want to use the returning value of "mean" and than displaying as a string, but I cant reach it from onCreate and I dont know how to do that. Here is the code:

public class DisplayMessageActivity extends Activity {

int[] x = {1, 2, 3, 4, 5, 6 ,7, 8 ,9, 10};

public static double mean(double[] x) {
    double sum = 0;
    for (int i = 0; i < x.length; i++) {
        sum += x[i];
    }
    return sum / x.length;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_display_message);

    getActionBar().setDisplayHomeAsUpEnabled(true);


    Intent intent = getIntent();
    String message = double.toString(mean);


    TextView textView = new TextView(this);
    textView.setTextSize(40);
    textView.setText(message);

    setContentView(textView);
}

Thanks for helping me out!

4

1 回答 1

0

但我无法从 onCreate 访问它,我不知道该怎么做。

可以达到它。您只是没有将双精度数组作为参数传递。

于 2013-06-17T15:29:59.063 回答