本文介绍了如何从依次显示每个值循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该计划给出了我的每一个值HTM的一个值。我想通过反复pressing计算按钮来依次显示每个值。我想,当我preSS它改变到i = 1,并显示由此计算的数值按钮它对于i = 0显示值,然后。
我知道我的问题是有点模糊,但你的帮助将是非常美联社preciated ..
问候

我的main.xml:

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:ID =@ + ID /主
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=垂直><的TextView
    机器人:ID =@ + ID / textView1
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_gravity =中心
    机器人:文字=最佳的倾斜角计算器
    机器人:textAppearance =:/>中的Andr​​oid ATTR / textAppearanceLarge?<按钮
    机器人:ID =@ + ID /按钮1
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_gravity =中心
    机器人:文字=计算/><的TextView
    机器人:ID =@ + ID /测试
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_gravity =中心
    机器人:文字=测试版=
    机器人:textAppearance =:/>中的Andr​​oid ATTR / textAppearanceLarge?<的TextView
    机器人:ID =@ + ID /拉德
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_gravity =中心
    机器人:文字=H =
    机器人:textAppearance =:/>中的Andr​​oid ATTR / textAppearanceLarge?


我的Tilt.java:

 包com.ned.tilt;    进口android.app.Activity;
    进口android.os.Bundle;
    进口android.view.View;
    进口android.widget.Button;
    进口android.widget.EditText;
    进口android.widget.TextView;    公共类倾斜延伸活动实现android.view.View.OnClickListener {
私有静态最后双PI = 3.142;
私有静态最后双PHI = 24.8508 *(PI / 180);
私有静态最后双GSC = 1367;
私有静态最后双RO = 0.2;
INT I,β,昂;双三角翼,WS,WSS,RB,Rb_num,Rb_den,RA,
        HTM,高程;
    双高清[] =新的双[12];
双千吨[] =新的双[12];
双坤[] =新的双[12];
双坎[] =新的双[12];
INT NBAR [] = {17,47,75,105,135,162,198,228,258,288,318,344};
INT N [] = {31,28,31,30,31,30,31,30,31,30,31,30};
双嗯[] = {4.38,5.18,5.93,6.65,6.67,6.40,5.44,5.27,5.62,5.24,
        4.5,4.11};
按钮CAL;
TextView的辐射角;@覆盖
公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);
    初始化();
    cal.setOnClickListener(本);}私人无效初始化(){
    // TODO自动生成方法存根
    CAL =(按钮)findViewById(R.id.button1);
    辐射=(的TextView)findViewById(R.id.rad);
    角=(的TextView)findViewById(R.id.beta);
}@覆盖
公共无效的onClick(视图v){
    // TODO自动生成方法存根
    对于(i = 0; I< = 11;我++){
        HTM = 0;
        三角洲= 23.45 *(Math.sin((0.986301369)*(PI / 180)
                *(284 +(NBAR [I]))));        WS = Math.acos( - (Math.tan(PHI))*(Math.tan(△*(PI / 180))));
        WS = WS *(180 / PI);        坤[I] = GSC
                *(1 +(0.033 * Math.cos(0.986301369 *(NBAR [I])
                        *(PI / 180))));        坎[我] =(86400 / PI)
                *坤[I]
                *(((Math.cos(PHI))*(Math.cos(增量*(PI / 180)))*(数学
                        .sin(WS *(PI / 180))))+((WS *(PI / 180))*(数学
                        .sin(PHI)*(Math.sin(△*(PI / 180))))));
        坎[我] =坎[I] / 3600000;        克拉[I] =嗯[I] /坎[我]        HD [I] =(0.96268) - ((1.45200)*(千吨[I]))
                +((0.27365)*(千吨[I])*(千吨[I]))
                +((0.04279)*(千吨[I])*(千吨[I])*(千吨[I]))
                +((0.000246)*(WS))
                +((0.001189)*(90 - (PHI *(180 / PI))+增量));
        HD [I] = HD [I] *嗯[I]
        对于(测试版= 0;&公测LT; = 90;测试++){
            WSS = Math.acos( - (Math.tan((PHI) - (测试版*(PI / 180)))*(数学
                    .tan(△*(PI / 180)))));
            WSS = WSS *(180 / PI);
            如果(WSS> WS){
                WSS = WS;
            }            Rb_num =((Math.cos((PHI) - (测试版*(PI / 180))))
                    *(Math.cos(增量*(PI / 180)))*(Math.sin(WSS
                    *(PI / 180))))
                    +(((PI / 180)* WSS)
                            *((Math.sin((PHI) - (测试版*(PI / 180)))))*((数学
                                .sin(△*(PI / 180)))));
            Rb_den =((Math.cos(PHI))*(Math.cos(增量*(PI / 180)))*(数学
                    .sin(WS *(PI / 180))))
                    +(((PI / 180)*(WS)*(Math.sin(PHI))*(数学
                            .sin(△*(PI / 180)))));
            RB = Rb_num / Rb_den;
            RA =((1 - (高清[I] /嗯[I]))*(RB))
                    +((高清[I] /(2 *了Hm [I]))*(1 +(Mat​​h.cos(测试版
                            *(PI / 180)))))
                    +((RO / 2)*(1 - (Math.cos(试用版*(PI / 180)))));            HT =镭*嗯[I]
            如果(HT> HTM){
                HTM =高程;
                ANG =β;
            }
        }        打破;
    }
    radiation.setText(H ​​=+ HTM);
    angle.setText(测试版=+ ANG);}
 }



解决方案

据我从你的问题明白了,你不应该用你的for循环

 为(i = 0; I< = 11;我++)

有关循环删除这一点,声明一个变量,并设置我来了,退出时的onClick增加你的变量。

 私人INT计数器= 0;公共无效的onClick(视图v){
    INT I =计数器;
    //一切还在继续,只是删除循环
    angle.setText(测试版=+ ANG);
    反++;
    如果(反== 12)计数器= 0; //你的阵列是固定的,所以我们义无反顾
}

This program gives one value of Htm for each value of i. I want to display each value in turn by repeatedly pressing the calculate button. I want it to display the values for i=0 and then when i press the button it changes to i=1 and displays the values thus calculated.I know my question is a bit vague, but your help will be really appreciated..Regards

My main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="Optimum Tilt Angle Calculator"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="Calculate" />

<TextView
    android:id="@+id/beta"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="Beta = "
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/rad"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="H = "
    android:textAppearance="?android:attr/textAppearanceLarge" />

My Tilt.java:

    package com.ned.tilt;

    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;

    public class Tilt extends Activity implements android.view.View.OnClickListener {
private static final double PI = 3.142;
private static final double PHI = 24.8508 * (PI / 180);
private static final double Gsc = 1367;
private static final double RO = 0.2;
int i, beta, ang;

double delta, ws, wss, Rb, Rb_num, Rb_den, Ra,
        Htm, Ht;
    double Hd[] = new double[12];
double Kt[] = new double[12];
double Gon[] = new double[12];
double Hom[] = new double[12];
int nbar[] = { 17, 47, 75, 105, 135, 162, 198, 228, 258, 288, 318, 344 };
int N[] = { 31, 28, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30 };
double Hm[] = { 4.38, 5.18, 5.93, 6.65, 6.67, 6.40, 5.44, 5.27, 5.62, 5.24,
        4.5, 4.11 };
Button cal;
TextView radiation, angle;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    initialize();
    cal.setOnClickListener(this);

}

private void initialize() {
    // TODO Auto-generated method stub
    cal = (Button) findViewById(R.id.button1);
    radiation = (TextView) findViewById(R.id.rad);
    angle = (TextView) findViewById(R.id.beta);
}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    for (i = 0; i <= 11; i++) {
        Htm = 0;
        delta = 23.45 * (Math.sin((0.986301369) * (PI / 180)
                * (284 + (nbar[i]))));

        ws = Math.acos(-(Math.tan(PHI)) * (Math.tan(delta * (PI / 180))));
        ws = ws * (180 / PI);

        Gon[i] = Gsc
                * (1 + (0.033 * Math.cos(0.986301369 * (nbar[i])
                        * (PI / 180))));

        Hom[i] = (86400 / PI)
                * Gon[i]
                * (((Math.cos(PHI)) * (Math.cos(delta * (PI / 180))) * (Math
                        .sin(ws * (PI / 180)))) + ((ws * (PI / 180)) * (Math
                        .sin(PHI) * (Math.sin(delta * (PI / 180))))));
        Hom[i] = Hom[i] / 3600000;

        Kt[i] = Hm[i] / Hom[i];

        Hd[i] = (0.96268) - ((1.45200) * (Kt[i]))
                + ((0.27365) * (Kt[i]) * (Kt[i]))
                + ((0.04279) * (Kt[i]) * (Kt[i]) * (Kt[i]))
                + ((0.000246) * (ws))
                + ((0.001189) * (90 - (PHI * (180 / PI)) + delta));
        Hd[i] = Hd[i] * Hm[i];
        for (beta = 0; beta <= 90; beta++) {
            wss = Math.acos(-(Math.tan((PHI) - (beta * (PI / 180))) * (Math
                    .tan(delta * (PI / 180)))));
            wss = wss * (180 / PI);
            if (wss > ws) {
                wss = ws;
            }

            Rb_num = ((Math.cos((PHI) - (beta * (PI / 180))))
                    * (Math.cos(delta * (PI / 180))) * (Math.sin(wss
                    * (PI / 180))))
                    + (((PI / 180) * wss)
                            * ((Math.sin((PHI) - (beta * (PI / 180))))) * ((Math
                                .sin(delta * (PI / 180)))));
            Rb_den = ((Math.cos(PHI)) * (Math.cos(delta * (PI / 180))) * (Math
                    .sin(ws * (PI / 180))))
                    + (((PI / 180) * (ws) * (Math.sin(PHI)) * (Math
                            .sin(delta * (PI / 180)))));
            Rb = Rb_num / Rb_den;
            Ra = ((1 - (Hd[i] / Hm[i])) * (Rb))
                    + ((Hd[i] / (2 * Hm[i])) * (1 + (Math.cos(beta
                            * (PI / 180)))))
                    + ((RO / 2) * (1 - (Math.cos(beta * (PI / 180)))));

            Ht = Ra * Hm[i];
            if (Ht > Htm) {
                Htm = Ht;
                ang = beta;
            }
        }

        break;
    }
    radiation.setText("H = " + Htm);
    angle.setText("Beta =" + ang);

}
 }


解决方案

As far as I understand from your question, you should not use your for loop

for (i = 0; i <= 11; i++)

Remove this for loop, Declare a variable, and set "i" to it, when exiting onClick increase your variable.

private int counter=0;

public void onClick(View v) {
    int i=counter;
    //everything continues, just remove the for loop
    angle.setText("Beta =" + ang);
    counter++;
    if(counter==12) counter=0;//your arrays are fixed, so we are turning back
}

这篇关于如何从依次显示每个值循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 18:06