First for every row in the list you need create a separate xml file which describes layout & text view for displaying the run-time data.
Also change ArrayAdapter to SimpleCursorAdapter that works well. In this change R.id.list as R.layout.text.xml i think it will work.... lv.setAdapter(new ArrayAdapter<String>(HelloWorld.this, R.id.list, arr)); For references check "ContactsManager" Application Android Developers site under resource tab. On Fri, Aug 13, 2010 at 1:45 AM, Warrior <[email protected]>wrote: > My bad.. there is another text.xml in the layout folder... > > <?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" > > > <ListView > android:id="@+id/list" > android:layout_width="wrap_content" > android:layout_height="wrap_content" > /> > </LinearLayout> > > On Aug 12, 3:22 pm, Erik R <[email protected]> wrote: > > On the line: > > lv = (ListView) findViewById(R.id.list); > > > > You are trying to get a handle on a ListView that does not exist in > > the XML that you are showing. > > > > On Aug 12, 1:34 pm, 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]<android-developers%[email protected]> > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- 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

