ListView Switch

  • Replies:0
  • OpenNot stickiedUnanswered
  • Forum posts: 1

Jan 10, 2016, 11:36:17 PM via Website

Hi! I´m working on an activity which shows all the apps installed on the phone, with its photo, name, and a switch.
For showing the apps, photo and name I´ve used this example: javatechig. com/android/how-to-get-list-of-installed-apps-in-android
For the switch I added

android:layout_height="fill_parent" android:gravity="center_vertical"
android:layout_gravity="center_vertical|right" />

to the snippet_list_row.xml .
I need the switch status to be changed and saves(using SharedPreferences) when an item of the ListView is clicked, so in, inside onListItemClick, I´ve put:

Switch appSwitch = (Switch) findViewById(; if
(appSwitch.isChecked()){ appSwitch.setChecked(false); }else{
appSwitch.setChecked(true); }
, String.valueOf(appSwitch.isChecked())).commit();

but it doesn´t work, and I don´t know why. Could somebody help me??
Thanks a lot

Recommended articles