2012-02-15 11 views
-2

talkPrice、textPrice、dataPriceを追加して合計をページのフィールドに表示したいのですが、私は迷っています。どんな助けも素晴らしいだろう。かなりそれは、私はちょうどそれがここ を追加する必要が一致するダブル<name>Priceを変更し、選択されたものに基づいて は、これまでのところ、私が持っているものであるAndroid追加ダブルナンバー

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) { 

    } 
} 
} 
+0

* _Do:

次に、あなたがこのような何かを行うことができます。お願いします。オーディンのひげで –

+0

私は何をお勧めしますか?ダブルプリミティブ? – ondrovic

+0

['BigDecimal'](http://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html)を使用してください。お願いします。 –

答えて

0

あなたはそれを表示するためのTextViewを作成し、参照を取得必要あなたのTextViewに。財務もののために*使用ダブルスNOT_ARCHIVEDの

textView.setText(String.valueOf(var1 + var2 + var3 + etc...)); 
関連する問題