获得零传递双重android

时间:2015-02-20 12:37:53

标签: android

我想知道为什么在我将双t传递给方法getListe();后,我的列表中为零?

我希望我的程序能够将输入值打印到列表中,但是当我添加“结果为零”时,我已经在onCreate方法中定义了双倍但我没有'认为它已被使用..

public class MainActivity extends ActionBarActivity
    implements BasicDialogFragment.OnNameEnteredListener {
    public static final String P1 = "melding";

    double l;
    double t;
    private static final String[] VERDIER =
                              {"Serielån", "Annuitetslån"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //input        = (EditText) findViewById(R.id.skrivTekst);
        listeKnapp   = (Button) findViewById(R.id.liste_button);
        final EditText laan = (EditText)findViewById(R.id.laanInput);
        final EditText aar = (EditText)findViewById(R.id.aarInput);
        final EditText termin = (EditText)findViewById(R.id.terminInput);
        final EditText rente = (EditText)findViewById(R.id.renteInput);
        final Spinner valgSpinner = (Spinner) findViewById(R.id.spinner1);

        double t = Double.parseDouble(termin.getText().toString());

        ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(
                this, android.R.layout.simple_spinner_item, VERDIER
        );
        valgSpinner.setAdapter(spinnerAdapter);



        listeKnapp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                visListe();
            }
        });
    }

    private String[] getListe(){

        String[] listeTabell = new String[50];
        for(int rad=0;rad<listeTabell.length;rad++) {
            listeTabell[rad] = "Dette er rad nr. " + rad + " " + 10 + " " + t;

        }
        return listeTabell;
    }
    private void visListe() {
        Intent i = new Intent(MainActivity.this, ListeDemo.class);
        Bundle b = new Bundle();
        b.putStringArray("no.hit.jon.liste", getListe());
        i.putExtra("no.hit.jon.listeBundle", b);
        startActivityForResult(i, 0);
    }

}

1 个答案:

答案 0 :(得分:0)

它是0,因为您将t声明为全局类成员,但从不使用它。

尝试将此添加到您的getListe()方法

private String[] getListe(){

    double t = Double.parseDouble(termin.getText().toString()); //Add this line

    String[] listeTabell = new String[50];
    for(int rad=0;rad<listeTabell.length;rad++) {
        listeTabell[rad] = "Dette er rad nr. " + rad + " " + 10 + " " + t;

    }
    return listeTabell;
}