2016-04-11 14 views
-2

budur i result1 harcanan para hesaplamak isteyennasıl bir tamsayı ileri götürmek için

static public String txtOrder =""; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_activityresult2); 

    Bundle bundle = getIntent().getExtras(); 
    String strfnq = bundle.getString("Noodle quantity"); 
    String strfrq = bundle.getString("Rice quantity"); 
    String strfsq = bundle.getString("Fish quantity"); 
    String stricq = bundle.getString("Iced tea"); 
    Integer strsum = bundle.getInt("sum"); 

    boolean addNingc = bundle.getBoolean("ANI"); 
    boolean addRingc = bundle.getBoolean("ARI"); 
    boolean addFingc = bundle.getBoolean("AFI"); 
    boolean addTingc = bundle.getBoolean("AIT"); 
    // boolean addmoneyc = bundle.getBoolean("AMY"); 

    Intent mIntent = getIntent(); 
    int sum = mIntent.getIntExtra("sum",strsum); 

    TextView costtext = (TextView)findViewById(R.id.costtext); 
    costtext.setText(getIntent().getExtras().getString("sum")); 

    TextView foodorders = (TextView) findViewById(R.id.foodordershow); 
    foodorders.setText(getIntent().getExtras().getString("Quantity")); 

    String addNdlThing = ""; 
    if (addNingc) { 
     addNdlThing = " with addition of ingredients"; 
    } 

    String addRlThing = ""; 
    if (addRingc) { 
     addRlThing = " with addition of ingredients"; 
    } 

    String addSlThing = ""; 
    if (addFingc) { 
     addSlThing = " with addition of ingredients"; 
    } 

    String addTeac = ""; 
    if (addTingc) { 
     addTeac = " with addition of ingredients"; 
    } 

    foodorders = (TextView) findViewById(R.id.foodordershow); 
    if(strfnq.equals("") && strfrq.equals("") && strfsq.equals("")&& stricq.equals("")){ 
     txtOrder = "Sorry, You've not ordered any thing , please return to previous menu to order"; 
    }else if (!strfnq.equals("") && !strfrq.equals("") && !strfsq.equals("")&& stricq.equals("")) { 
     txtOrder = "Thank you , You've ordered\n" + strfnq + " fried noodle" + addNdlThing +" and\n"+ strfrq 
       + " fried rice" + addRlThing +" and\n" + strfsq + " Steam fish " + addSlThing + "and\n" + stricq + " Steam fish " + addTeac; 
    } else { 
     txtOrder = "Thank you , You've ordered\n"; 
     if(!strfnq.equals("")){ 
      txtOrder = txtOrder + strfnq + " fried noodle" + addNdlThing; 
     } 
     if(!strfrq.equals("")){ 
      txtOrder = txtOrder + strfrq + " fried rice" + addRlThing; 
     } 
     if(!strfsq.equals("")){ 
      txtOrder = txtOrder + strfsq + " Steam fish" + addSlThing; 
     } 
     if(!stricq.equals("")){ 
      txtOrder = txtOrder + stricq + " Iced Tea"+ addTeac; 
     } 
    } 
    foodorders.setText(txtOrder); 
} 

activityresult2 ve görüntülemek için activityresult1 hesaplanan toplamı gönderilen nasıl

Button buttonorder; 
TextView textviewcard; 
private static final int REQUEST_CODE = 10; 
int[] image ={R.drawable.friednoodle, R.drawable.friedrice, R.drawable.steamfish,R.drawable.tehice}; 
String[] item = {"Fried Noodle", "Fried Rice", "Steam Fish","Iced Tea"}; 
String[] description = {"Classic Chinese stir fried noodle with prawn and Pork", "Special sauce Fried Rice using indian rice", "HongKong Style Steamed Fish ","HongKong classical iced tea"}; 
String[] cost={"6","5","25","2"}; 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_activityresult1); 

    Bundle extras = getIntent().getExtras(); 
    String strcardnumber = extras.getString("Card Number"); 
    textviewcard = (TextView) findViewById(R.id.textviewcard); 
    textviewcard.setText("Welcome, " + strcardnumber + " !" + "\nPlease select the food you want ! : "); 

    itemList = new ArrayList<DataInfo>(); 
    itemList.add(new DataInfo(item[0], image[0], description[0], cost[0])); 
    itemList.add(new DataInfo(item[1], image[1], description[1], cost[1])); 
    itemList.add(new DataInfo(item[2], image[2], description[2], cost[2])); 
    itemList.add(new DataInfo(item[3], image[3], description[3], cost[3])); 

    final MenuAdapter adapter = new MenuAdapter(this); 

    ListView listView = (ListView)findViewById(R.id.list); 
    LVAdapter lvAdapter = new LVAdapter(this, itemList); 
    //listView.setAdapter(lvAdapter); 

    listView.setAdapter(adapter); 

    for (int i = 0; i < item.length; i++) { 
     adapter.addData(String.valueOf(i), item[i], image[i], description[i], cost[i]); 
    } 

    buttonorder = (Button) findViewById(R.id.suborder); 
    buttonorder.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
     String[] a = adapter.getQuantity(); 
      Toast.makeText(getApplicationContext(), "Noodle: " + a[0] + "\nRice: " + a[1] + "\nSteam fish: " + a[2] + "\nIced tea: " + a[3], Toast.LENGTH_LONG).show(); 

      int sum = Integer.parseInt(adapter.getQuantity()[0])*Integer.parseInt(cost[0]) + 
        Integer.parseInt(adapter.getQuantity()[1])*Integer.parseInt(cost[1]) + 
        Integer.parseInt(adapter.getQuantity()[2])*Integer.parseInt(cost[2]) + 
        Integer.parseInt(adapter.getQuantity()[3])*Integer.parseInt(cost[3]); 

      Intent myIntent = new Intent(activityresult1.this, activityresult2.class); 
      myIntent.putExtra("sum",sum); 
      startActivity(myIntent); 

      Intent intent = new Intent(getApplicationContext(), activityresult2.class); 
      Bundle bundle = new Bundle(); 
      bundle.putString("Noodle quantity", adapter.getQuantity()[0]); 
      bundle.putString("Rice quantity", adapter.getQuantity()[1]); 
      bundle.putString("Fish quantity", adapter.getQuantity()[2]); 
      bundle.putString("Iced tea", adapter.getQuantity()[3]); 
      bundle.putInt("sum", sum); 
      bundle.putBoolean("ANI", adapter.getItem(0).isAddInisCheck());//add noodle ingredients 
      bundle.putBoolean("ARI", adapter.getItem(1).isAddInisCheck()); // add rice ingredients 
      bundle.putBoolean("AFI", adapter.getItem(2).isAddInisCheck());// add fish ingredients 
      bundle.putBoolean("AIT", adapter.getItem(3).isAddInisCheck()); // add ice tea ingredients 
      intent.putExtras(bundle); 
      startActivityForResult(intent, REQUEST_CODE); 
     } 
    }); 
} 

activityresult1 sonucu 2 Ben altta yazdıkları yöntemi kullanmayı denedim ama bazıları için doldurmak için ne bilmiyorum gibi çalışmıyor. lütfen bana yardım edin, gerçekten bu konuda yardıma ihtiyacım var, ve ben çok sayım kodları var dediğim gibi, yazı yazabilmem için kelime sayımı yapmak için çok yazdım ve lütfen bu gönderiden hoşlanmayı bırakmayın, böyle kişiler olmayın, bu i bir sonraki activity için sum değerini gönderilen edebilirsiniz

cevap

2

aptalım ve bunun gibi diğer activity yılında Bundle yoluyla almak anlamına daha dont soruyu soran iki taraf için mutlu olacak. senin activity B

Intent i= new Intent(this,B.class); 
i.putExtra("sum",sum); 
startActivity(i); 

göndermeden olduğunu sen

getApplicationContext() Sonra activity B size onCreate() yönteminde bu satırları ekleyebilir, aşağıdaki this, getActivity() birini birinden activity B için context gönderebilir düşünün iletilen içeriği almak için

Bundle MainActivityData= getIntent().getExtras(); 
int sum= MainActivityData.getString("sum"); 
+0

Üzgünüm, anlayamadım, bana e-posta gönderebilirsiniz [email protected] –

+0

Bunu eklemeye çalıştım ama altında kırmızı çizgiler var –

+0

İlk satır, Intent (this, B.class); B için ne yazarım ve bundan sonra paket aktivitesini kopyalarım ama –