Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid listview toggle button
    text
    copied!<p>I have a <code>Listview</code> that will list the alarms which are in the database.I need to add a <code>Toggle</code> Button beside each list item to set the alarm on/off.</p> <p>How can I add the <code>Toggle</code> Button in the <code>ListView</code>?</p> <p><code>R.layout.alarm_list</code>:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt; &lt;ListView android:id="@+id/android:list" android:layout_width="fill_parent" android:layout_height="fill_parent"/&gt; &lt;TextView android:id="@+id/android:empty" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/no_reminders" android:textColor="#FFF"/&gt; &lt;/LinearLayout&gt; </code></pre> <p>Java Code:</p> <pre><code> private void fillData() { Cursor remindersCursor = aDbHelper.fetchAllAlarms(); startManagingCursor(remindersCursor); // Create an array to specify the fields we want to display in the list // (only TITLE) String[] from = new String[] { AlarmDbAdapter.KEY_TITLE }; // and an array of the fields we want to bind those fields to (in this // case just text1) int[] to = new int[] { R.id.text1}; // Now create a simple cursor adapter and set it to display SimpleCursorAdapter reminders = new SimpleCursorAdapter(this, R.layout.alarm_row, remindersCursor, from, to); setListAdapter(reminders); } </code></pre> <p><code>R.layout.alarm_row</code>:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/text1" android:padding="10dip" android:layout_width="242dp" android:layout_height="wrap_content"/&gt; </code></pre> <p>My project is getting delayed.</p> <p>Help </p>
 

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