Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Depending on whether your data in the second activity is from a database or static data, this code should work for you. I am assuming from your post that you dont need to send data from the 1st activity to the 2nd activity. This is actual code from my application which is database driven. If you are not using a database, parts of this code can be changed to use that instead of a database. It should get you started:</p> <p>From the 1st Activity:</p> <pre><code>public void onClickListContacts(View target) { Intent listContacts = new Intent(this, com.dzinesunlimited.quotetogo.ContactsList.class); startActivity(listContacts); } </code></pre> <p>The 2nd activity:</p> <pre><code>public class ContactsList extends ListActivity { DBAdapter dbContactList; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.contacts_list); dbContactList = new DBAdapter(this); // Calls the method to display the ListView of all Contacts fillData(); } private void fillData() { // Pull the data from the database String[] fields = new String[] { dbContactList.TABLE_CON_NAME }; int[] views = new int[] { android.R.id.text1 }; Cursor c = dbContactList.getAllContacts(); startManagingCursor(c); // Set the ListView ListAdapter prjName = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, c, fields, views); setListAdapter(prjName); dbContactList.close(); } </code></pre> <p>For a static list, you can also refer to this tutorial: <a href="http://www.vogella.de/articles/Android/article.html#lists" rel="nofollow">http://www.vogella.de/articles/Android/article.html#lists</a></p> <p>Hope this helps.</p> <p>PS: It would be great help if you could post code of the 2nd activity which has problems.</p> <p>Add this to your XML and see if that helps:</p> <pre><code>&lt;ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" &gt; &lt;/ListView&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload