Android添加双号码

时间:2012-02-15 01:29:30

标签: java android

我想添加talkPrice,textPrice和dataPrice并将总数显示在页面上的字段中,但我不知所措。任何帮助都会很棒。 几乎基于所选内容,它会更改Double <name>Price以匹配我只需要它来添加 这是我到目前为止所拥有的

package com.bestbuymobile;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;

public class att_ind extends Activity{
String debug = "ATT_IND";
Double talkPrice = 0.00;
Double textPrice = 0.00;
Double dataPrice = 0.00;
Double totalPrice = 0.00; 

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.att_ind_layout);
        Log.d(debug,"Calling Talk_Plans Function");
        Talk_Plans();
        Log.d(debug,"Calling Text_Plans Function");
        Text_Plans();
        Log.d(debug,"Calling Data_Plans Function");
        Data_Plans();
}
public void Talk_Plans() {
    Log.d(debug,"");
    Spinner talk = (Spinner) findViewById(R.id.att_ind_talk_spinner);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.att_ind_talk_plans, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    talk.setAdapter(adapter);
    talk.setOnItemSelectedListener(new Talk());
}
public void Text_Plans() {
    Log.d(debug,"");
    Spinner text = (Spinner) findViewById(R.id.att_ind_text_spinner);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.att_ind_text_plans, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    text.setAdapter(adapter);
    text.setOnItemSelectedListener(new Text());
}
public void Data_Plans() {
    Log.d(debug,"");
    Spinner data = (Spinner) findViewById(R.id.att_ind_data_spinner);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.att_ind_data_plans, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    data.setAdapter(adapter);
    data.setOnItemSelectedListener(new Data());
}

class Talk implements OnItemSelectedListener {
    public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {

        Log.d(debug,"Listening for Talk packages");
        if(parent.getItemAtPosition(pos).toString().equals("None")) {
            Log.d(debug,"No talk package selected");
            textPrice = 0.00;
        }
        if(parent.getItemAtPosition(pos).toString().equals("450 Minutes")) {
            Log.d(debug,"450 Minute package selected");
            textPrice = 39.99;
        }
        if(parent.getItemAtPosition(pos).toString().equals("900 Minutes")) {
            Log.d(debug,"900 Minute package selected");
            textPrice = 59.99;
        }
        if(parent.getItemAtPosition(pos).toString().equals("Unlimited Minutes")) {
            Log.d(debug,"Unlimited Minute package selected");
            textPrice = 69.99;
        }
    }
    public void onNothingSelected(AdapterView<?> parent) {

    }
}
class Text implements OnItemSelectedListener {
    public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
        Log.d(debug,"Listening for Text packages");
        if(parent.getItemAtPosition(pos).toString().equals("None")) {
            Log.d(debug,"No messaging package selected");
            textPrice = 0.00;
        }
        if(parent.getItemAtPosition(pos).toString().equals("Unlimited")) {
            Log.d(debug,"Unlimited Messaging package selected");
            textPrice = 20.00;
        }
    }
    public void onNothingSelected(AdapterView<?> parent) {

    }
}
class Data implements OnItemSelectedListener {
    public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
        Log.d(debug,"Listening for Data packages");
        if(parent.getItemAtPosition(pos).toString().equals("None")) {
            Log.d(debug,"No data package selected");
            dataPrice = 0.00;
        }
        if(parent.getItemAtPosition(pos).toString().equals("300 MB")) {
            Log.d(debug,"300MB data package selected");
            dataPrice = 20.00;
        }
        if(parent.getItemAtPosition(pos).toString().equals("3 GB")) {
            Log.d(debug,"3GB data package selected");
            dataPrice = 30.00;
        }
        if(parent.getItemAtPosition(pos).toString().equals("5 GB")) {
            Log.d(debug,"5GB data package selected");
            dataPrice = 50.00;
        }
    }
    public void onNothingSelected(AdapterView<?> parent) {

    }
}
}

1 个答案:

答案 0 :(得分:0)

您需要创建一个TextView来显示它,并获得对TextView的引用。

然后你可以这样做:

textView.setText(String.valueOf(var1 + var2 + var3 + etc...));