Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>replace with this, i correctly formatted it for you</p> <pre><code>import java.util.ArrayList; import android.app.ListActivity; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; 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.TextView; import android.widget.Toast; public class Main1Activity extends ListActivity { private static final String DB_NAME = "yourdb.sqlite3"; // A good practice is to define database field names as constants private static final String TABLE_NAME = "friends"; private static final String FRIEND_ID = "_id"; private static final String FRIEND_NAME = "name"; private SQLiteDatabase database; private ListView listView; private ArrayList friends; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main1); // Our key helper ExternalDbOpenHelper dbOpenHelper = new ExternalDbOpenHelper(this, DB_NAME); database = dbOpenHelper.openDataBase(); // That’s it, the database is open! fillFreinds(); setUpList(); } private void setUpList() { // We use a standard adapter and an element layout for brevity’s sake setListAdapter(new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, friends)); listView = getListView(); // Let’s set a message shown upon tapping an item listView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView parent, View view, int position, long id) { Toast.makeText( getApplicationContext(), ((TextView) view).getText() + " could be Softeq's friend", Toast.LENGTH_SHORT).show(); } }); } // Extracting elements from the database private void fillFreinds() { friends = new ArrayList&lt;String&gt;(); Cursor friendCursor = database.query(TABLE_NAME, new String[] { FRIEND_ID, FRIEND_NAME }, null, null, null, null, FRIEND_NAME); friendCursor.moveToFirst(); if (!friendCursor.isAfterLast()) { do { String name = friendCursor.getString(1); friends.add(name); } while (friendCursor.moveToNext()); } friendCursor.close(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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