I'm not sure what you're trying to ask.  You should try phrasing your
question differently.
So I think you're asking how to populate a listview and save its
between activities.
What you could do is create a top Application class.
First you'd modify your AndroidManifest.xml file like so:

<application android:name="YourApp">
       <activity ...>
        </activity>
    <activity ...>
    </activity>
</application>

Then create a YourApp.java class that extends the 'Application' class.
You can then put your ArrayAdapter in there and it'll stay saved
between activities.


On Thu, Aug 12, 2010 at 11:34 AM, Warrior <[email protected]> wrote:
> can anyone tell me whats wrong or suggest the best way to populate a
> ListView on runtime from one screen to another.
> Please see my code below
> 1. the list always ends up empty
> 2. I get a invalid resource error in the end.
>
> <?xml version="1.0" encoding="utf-8"?>
> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/
> android"
>    android:orientation="vertical"
> android:layout_width="fill_parent"
> android:layout_height="fill_parent" >
> <TextView
>    android:layout_width="fill_parent"
> android:layout_height="wrap_content" android:text="@string/hello" />
> <EditText
> android:id="@+id/entry" android:layout_width="fill_parent"
> android:layout_height="wrap_content"
> android:background="@android:drawable/editbox_background"/>
> <Button     android:id="@+id/ok"
> android:layout_width="wrap_content"
> android:layout_height="wrap_content"   android:layout_below="@id/
> entry"    android:layout_alignParentRight="true"
> android:layout_marginLeft="10dip"    android:text="Add to List" />
> <Button   android:id="@+id/viewlist"
> android:layout_width="wrap_content"
>        android:layout_height="wrap_content"
> android:layout_below="@id/ok"
>        android:layout_alignParentRight="true"
> android:layout_marginLeft="10dip"
>        android:text="View List" />
> </LinearLayout>
>
> public class HelloWorld extends Activity {
>
>    /** Called when the activity is first created. */
>
>        public ListView lv;
>        public ArrayList<String> arr = new ArrayList<String>();
>
>   �...@override
>    public void onCreate(Bundle savedInstanceState) {
>        super.onCreate(savedInstanceState);
>        setContentView(R.layout.main);
>
>        Button okButton = (Button) findViewById(R.id.ok);
>        okButton.setOnClickListener(new View.OnClickListener() {
>            public void onClick(View v) {
>                EditText et = (EditText) findViewById(R.id.entry);
>                arr.add(et.getText().toString());
>                Toast.makeText(HelloWorld.this, "Added: " + et.getText(),
> Toast.LENGTH_SHORT).show();
>                et.bringToFront();
>            }
>        });
>
>        Button viewListButton = (Button) findViewById(R.id.viewlist);
>        viewListButton.setOnClickListener(new View.OnClickListener() {
>            public void onClick(View v) {
>                setContentView(R.layout.text);
>                lv = (ListView) findViewById(R.id.list);
>                lv.setAdapter(new
> ArrayAdapter<String>(HelloWorld.this, R.id.list, arr));
>            }
>        });
>    }
> }
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en



-- 
http://developingthedream.blogspot.com/,
http://diastrofunk.com,
http://www.youtube.com/user/revoltingx, ~Isaiah 55:8-9

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

Reply via email to