I hope someone can help.  

I have an application that I am building that currently has 3 main Layouts. 
All String-Arrays are in XML.  First Screen Shows, Breakfast, Lunch & 
Dinner.  Now depending on which Button is selected, Example "Lunch" a 2nd 
Layout comes up Showing the Lunch Menu items, such as Cheeseburger, 
Hamburger, Hot Dog, French Fries, Onion Rings...  Let's say I select 
"Cheeseburger", the Item is Added to the 3rd Layout.  When I click the Back 
button on the phone and select a new item such as "Onion Rings" that item 
replaces the Cheeseburger.  I need it to ADD it to the List, not replace 
it.  Can someone please tell me where my code is wrong?  

Summary,  I need the list to get appended with the items selected, not 
replaced by the selected item.


Here is my lunchActivity.java

[CODE]
package com.mycompany.foodmenu;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
 
public class lunchActivity extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.lunchmain);
        final ListView lv=(ListView)findViewById(R.id.listView1);           
   
        ArrayAdapter<CharSequence> 
adapter=ArrayAdapter.createFromResource(this, 
R.array.lunch_menu,android.R.layout.simple_list_item_1);
        lv.setAdapter(adapter);
        lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long 
arg3) {
   // TODO Auto-generated method stub 
        String item=lv.getItemAtPosition(arg2).toString();
   String itemordered;
   itemordered = item + " added to list";
   Toast.makeText(getApplicationContext(), itemordered, 
Toast.LENGTH_LONG).show();
   
            // Launching new Activity on selecting List Item
            Intent i = new Intent(getApplicationContext(), ListItem.class);
            // sending data to new activity
            i.putExtra("item", item);
            startActivity(i); 
    }
        });
    }
}
[/CODE]

Here is the lunch.xml menu file that read by the lunchActivity to create 
the first ListView

[CODE]
<resources>
    
    <string-array name="lunch_menu">
<item>Cheeseburger</item>
<item>Hamburger</item>
<item>Bacon Cheeseburger</item>
<item>Hot Dog</item>
<item>French Fries</item>
<item>Onion Rings</item>
    </string-array>
    
</resources>
[/CODE]

Here is the listItem.java

[CODE]
package com.mycompany.foodmenu;

import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class listItem extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.selecteditems);

    Intent i = getIntent();

    ArrayList<String> myNewList = new ArrayList<String>();
    String item = i.getStringExtra("item");

    myNewList.add(item);
    ListView selecteditems = (ListView) findViewById(R.id.listitems);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(ListItem.this, 
android.R.layout.simple_list_item_1, myNewList);
    selecteditems.setAdapter(adapter);
    // adapter.notifyDataSetChanged(); 


    }
}
[/CODE]

BTW.  I have tried changing [CODE]myNewList.add(item);[/CODE]  to 
[CODE]myNewList.addAll(item);[/CODE] and it just creates new problems.  I 
have also tried adding [CODE]adapter.notifyDataSetChanged();[/CODE] to the 
end and it makes no difference.

And here is the selectedItems.xml file that is suppose to get populated 
with the Selected Items from the Lunch Menu

[CODE]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android";
  android:orientation="vertical"
  android:background="@drawable/main_background" 
  android:paddingLeft="10.0dip" 
  android:paddingTop="0.0dip" 
  android:paddingRight="10.0dip" 
  android:paddingBottom="10.0dip" 
  android:layout_width="fill_parent" 
  android:layout_height="fill_parent">

          <ListView 
              android:id="@+id/listitems"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:textSize="25dip"
              android:textStyle="bold"
              android:padding="10dip"
              android:textColor="#ffffff"/>

</LinearLayout>
[/CODE]

Any help would be greatly appreciated!!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to