Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have a similar function in my app. You will need to create a XML file to define the layout for the list and call them in your java code.</p> <p>Here is the example XML:</p> <p>LIST:</p> <pre><code>&lt;LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="vertical" &gt; &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; &lt;TextView android:id="@+id/android:empty" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="@string/no_projects" android:padding="10dp" android:textSize="16sp" android:textStyle="bold" &gt; &lt;/TextView&gt; &lt;/LinearLayout&gt; </code></pre> <p>This is the custom layout XML. I call it list_rows:</p> <pre><code>&lt;LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="vertical" &gt; &lt;TextView android:id="@+id/text1" android:layout_width="fill_parent" android:layout_height="wrap_content"&gt; &lt;/TextView&gt; &lt;TextView android:id="@+id/text2" android:layout_width="fill_parent" android:layout_height="wrap_content"&gt; &lt;/TextView&gt; &lt;TextView android:id="@+id/text3" android:layout_width="fill_parent" android:layout_height="wrap_content"&gt; &lt;/TextView&gt; &lt;/LinearLayout&gt; </code></pre> <p>And this is the JAVA code:</p> <pre><code>String[] fields = new String[] { db.TABLE_PRJ_NAME, db.TABLE_PRJ_TYPE, db.TABLE_PRJ_DESC }; int[] views = new int[] { /*android.R.id.text1*/ R.id.text1, R.id.text2, R.id.text3 }; c = db.getAllProjects(); startManagingCursor(c); // Set the ListView SimpleCursorAdapter prjName = new SimpleCursorAdapter( this, R.layout.project_list_rows, //android.R.layout.simple_list_item_1, c, fields, views); setListAdapter(prjName); </code></pre> <p>The onListItemClickListener</p> <pre><code>// This section of code is for handling the Click Event of the Projects List @Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); Cursor o = (Cursor) this.getListAdapter().getItem(position); String projectName = o.getString(1); Intent showProjectDetails = new Intent(this, ProjectDetails.class); Bundle bundle = new Bundle(); bundle.putString("sendProjectName", projectName); showProjectDetails.putExtras(bundle); startActivity(showProjectDetails); } </code></pre> <p>What the new part of the code is doing is just sending the selected item to another activity through an intent. Then in the new activity, I am querying the DB using the selected item name from the bundle and displaying the result.</p> <p>Do ask if you need further explanation.</p>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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