私はさまざまな食品や飲み物の量を選択できるレストランメニューアプリを作成しようとしています。第2のビューに「あなたの合計は_____」と表示されます。しかし、私は大量のエラーが発生しています。誰かが私を助けることができたら、私はそれを感謝します。私はこれに非常に新しいので、私はこのサイトの他の質問からの他の答えから一緒にステッチしました。ありがとうございました!Android:1つのビューから別のビューに2つの値を渡す際に助けが必要
メインアクティビティビュー:
package name.restaurantmenu2;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
double totalPrice = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CheckBox pizzaCB = (CheckBox)findViewById(R.id.cb_pizza);
if(pizzaCB.isChecked()){
pizzaCB.toggle();
}
CheckBox burgerCB = (CheckBox)findViewById(R.id.cb_hamburger);
if(burgerCB.isChecked()){
burgerCB.toggle();
}
CheckBox hotdogCB = (CheckBox)findViewById(R.id.cb_hotdog);
if(hotdogCB.isChecked()){
hotdogCB.toggle();
}
CheckBox sodaCB = (CheckBox)findViewById(R.id.cb_soda);
if(sodaCB.isChecked()){
sodaCB.toggle();
}
}
public void addSelected(View view){
String multiple;
CheckBox pizzaCB = (CheckBox)findViewById(R.id.cb_pizza);
CheckBox burgerCB = (CheckBox)findViewById(R.id.cb_hamburger);
CheckBox hotdogCB = (CheckBox)findViewById(R.id.cb_hotdog);
CheckBox sodaCB = (CheckBox)findViewById(R.id.cb_soda);
TextView pizzaTV = (TextView)findViewById(R.id.tv_pizzaPrice);
TextView burgerTV = (TextView)findViewById(R.id.tv_hamburgerPrice);
TextView hotdogTV = (TextView)findViewById(R.id.tv_hotdogPrice);
TextView sodaTV = (TextView)findViewById(R.id.tv_sodaPrice);
Spinner pizzaQty = (Spinner)findViewById(R.id.spinner_pizzaQuantity);
Spinner burgerQty = (Spinner)findViewById(R.id.spinner_hamburgerQuantity);
Spinner hotdogQty = (Spinner)findViewById(R.id.spinner_hotdogQuantity);
Spinner sodaQty = (Spinner)findViewById(R.id.spinner_drinks);
if(pizzaCB.isChecked()) {
String value = pizzaTV.getText().toString();
value = value.replace('$', ' ');
multiple = String.valueOf(Double.parseDouble(pizzaQty.getSelectedItem().toString()) * Double.parseDouble(value));
totalPrice++;
}
if(burgerCB.isChecked()) {
String value = burgerTV.getText().toString();
value = value.replace('$', ' ');
multiple = String.valueOf(Double.parseDouble(burgerQty.getSelectedItem().toString()) * Double.parseDouble(value));
totalPrice++;
}
if(hotdogCB.isChecked()) {
String value = hotdogTV.getText().toString();
value = value.replace('$', ' ');
multiple = String.valueOf(Double.parseDouble(hotdogQty.getSelectedItem().toString()) * Double.parseDouble(value));
totalPrice++;
}
if(sodaCB.isChecked()) {
String value = sodaTV.getText().toString();
value = value.replace('$', ' ');
multiple = String.valueOf(Double.parseDouble(sodaQty.getSelectedItem().toString()) * Double.parseDouble(value));
totalPrice++;
}
}
public void onTotalClick(View view){
Intent intent = new Intent(this, ComputedActivity.class);
Bundle b = new Bundle();
b.putDouble(totalPrice, double);
intent.putExtras(b);
startActivity(intent);
}
}
ビューまず2
package name.restaurantmenu2;
import android.annotation.TargetApi;
import android.content.Intent;
import android.icu.text.NumberFormat;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.TextView;
public class ComputedActivity extends AppCompatActivity {
public static final String EXTRA_MESSAGE = "Nothing to display";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_computed2);
}
@TargetApi(Build.VERSION_CODES.N)
private void displayPrice(double number){
Bundle b = getIntent().getExtras();
double result = b.getDouble(totalPrice);
TextView priceTextView = (TextView)findViewById(R.id.tv_totalPrice);
priceTextView.setText(NumberFormat.getCurrencyInstance().format(number));
}
}
最初のエラーは何ですか? –
エラーは何ですか?ログcatを貼り付けてください – suku