I have a Listview that will list the alarms that are in the database. I need to add a Toggle button next to each list item in order to enable / disable the alarm.
How to add Toggle button in Listview ?
R.layout.alarm_list :
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ListView android:id="@+id/android:list" android:layout_width="fill_parent" android:layout_height="fill_parent"/> <TextView android:id="@+id/android:empty" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/no_reminders" android:textColor="#FFF"/> </LinearLayout>
Java 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); }
R.layout.alarm_row :
<?xml version="1.0" encoding="utf-8"?> <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"/>
My project is delayed.
reference
source share