我現在正面臨此問題。我想生成食物收據及其價格和總價格(所有選中複選框的總和 - 所選菜單)如何在用戶選中複選框時指定整數值
這是複選框頁面的代碼,用戶需要在其中檢查項目喜歡購買。
<RelativeLayout >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<CheckBox
android:id="@+id/pakejC1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Beg" />
<CheckBox
android:id="@+id/pakejC2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Shoes" />
<ImageButton
android:id="@+id/gobutton"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignTop="@+id/homebtn"
android:layout_toRightOf="@+id/homebtn"
android:background="@drawable/gobutton"
android:onClick="goReceiptC" />
這是流程
public class item extends Activity
{
CheckBox beg1, shoes1;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.item);
beg1 = (CheckBox) findViewById(R.id.pakejC1);
shoes1 = (CheckBox) findViewById(R.id.pakejC2);
}
public void goReceiptC(View v)
{
Intent intent = new Intent(v.getContext(), doReceiptC.class);
intent.putExtra("beg1", beg1.isChecked());
intent.putExtra("shoes1", shoes1.isChecked());
startActivityForResult(intent,0);
}
}
這個代碼是用以顯示收到
public class doReceipt extends Activity
{
boolean beg1, shoes1;
TextView tvOutput1,tvOutput2;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.receipt);
tvOutput1 = (TextView) findViewById(R.id.textView1);
tvOutput2 = (TextView) findViewById(R.id.textView2);
Bundle data = this.getIntent().getExtras();
beg1=data.getBoolean("beg1");
shoes1=data.getBoolean("shoes1");
if(beg2==true)
{
tvOutput1.setText("Nasi Putih RM 1.00");
tvOutput1.setVisibility(View.VISIBLE);
// this is where i would like to display the price
//eg rm 1.00
}
else
{
tvOutput1.setVisibility(View.GONE);
}
if (shoes1==true)
{
tvOutput2.setText("shoes RM 1.50");
tvOutput2.setVisibility(View.VISIBLE);
// this is where i would like to display the price
//eg rm 1.50
}
else
{
tvOutput2.setVisibility(View.GONE);
}
**我想要的總價都檢查項目是顯示的過程在收據上合計
這是顯示收據的頁面
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textA"
android:layout_below="@+id/textA"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/textView1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/textView1"
android:text="total price"
android:textAppearance="?android:attr/textAppearanceMedium" />
幫我PLZ ....
從哪裏獲得價值? 1.50和1? – 2014-09-30 08:07:14
我自己分配價值 – 2014-10-01 00:53:00