2013-09-22 51 views
0

我設法從單選按鈕做合格值,現在我想在幾個複選框用戶點擊到一起舉杯視圖+澆頭顯示檢查的值:這裏Android的傳球值

package com.example.pizzaorderding; 

import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 
import android.view.View; 
import android.widget.Button; 
import android.widget.CheckBox; 
import android.widget.EditText; 
import android.widget.RadioButton; 
import android.widget.RadioGroup; 
import android.widget.Toast; 

public class MainActivity extends Activity { 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 


     final EditText name=(EditText)findViewById(R.id.name); 
     final EditText phone=(EditText)findViewById(R.id.phone_number); 
     final EditText address=(EditText)findViewById(R.id.address); 
     final RadioGroup shapes = (RadioGroup) findViewById(R.id.rBtnshapes); 
     final RadioGroup types = (RadioGroup) findViewById(R.id.rBtntypes); 
     final CheckBox pep = (CheckBox)findViewById(R.id.pepperoni); 
     final CheckBox mshr = (CheckBox)findViewById(R.id.mushrooms); 

     Button orderBtn = (Button)findViewById(R.id.orderBtn); 

     orderBtn.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       StringBuffer result = new StringBuffer(); 
       result.append("Pepperoni").append(pep.isChecked()); 
       result.append("Mushrooms").append(mshr.isChecked()); 

       int selectedShape = shapes.getCheckedRadioButtonId(); 
       int selectedCheese = types.getCheckedRadioButtonId(); 
       RadioButton sh = (RadioButton)findViewById(selectedShape); 
       RadioButton ty=(RadioButton)findViewById(selectedCheese); 
       Toast.makeText(MainActivity.this, "Name: "+name.getText()+"\n"+"Phone: "+phone.getText()+"\n"+"Address: " +address.getText()+"\n"+"Shape: "+sh.getText()+"\n"+"Cheese: "+ty.getText()+"\n"+"Toppings: "+result.toString(), Toast.LENGTH_SHORT).show(); 
      } 
     }); 

    } 

} 
+0

這是什麼問題?你有什麼問題? – codeMagic

回答

0

也許這會工作?

result.append("Pepperoni").append(pep.isChecked().toString()); 
result.append("Mushrooms").append(mshr.isChecked().toString()); 
0

你的意思是這樣的:

if (pep.isChecked()) 
    result.append("Pepperoni, "); 
if (mshr.isChecked()) 
    result.append("Mushrooms, "); 
if (result.length() > 2) 
    result.delete(result.length() - 2, result.length()); // to remove last ", " 
0

public void onClick(View v) { // TODO Auto-generated method stub StringBuffer result = new StringBuffer(); result.append("Pepperoni"+"\n").append(pep.isChecked()).toString(); result.append("Mushrooms"+"\n").append(mshr.isChecked()).toString();

  int selectedShape = shapes.getCheckedRadioButtonId(); 
      int selectedCheese = types.getCheckedRadioButtonId(); 
      RadioButton sh = (RadioButton)findViewById(selectedShape); 
      RadioButton ty=(RadioButton)findViewById(selectedCheese); 
      Toast.makeText(MainActivity.this, "Name: "+name.getText()+"\n"+"Phone: "+phone.getText()+"\n"+"Address: " +address.getText()+"\n"+"Shape: "+sh.getText()+"\n"+"Cheese: "+ty.getText()+"\n"+"Toppings: "+result.toString(), Toast.LENGTH_SHORT).show(); 

` 這是如何顯示http://postimg.org/image/zc1dobpuf/ ..我不想要顯示真或假,只是如果它被檢查以顯示頂部