Android : Checkbox doesnt change visual

on Friday, September 12, 2014


i have an Activity with a LinearLayout, containing a TextView, a CheckBox and a Button. When i check the CheckBox nothing visible happens, however it behaves correctly. However, when i click on the Button, then the CheckBox is displayed correctly for a moments before the Activity closes(as it should). Also the option is set correctly, so the state of the CheckBox does really change, but it doesn't display the change. Here is my code:


activity_setup_hint.xml



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context="${packageName}.${activityClass}" >

<LinearLayout
android:background="@drawable/info_box_inset"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:padding="20dp">

<de.myProject.util.FontTextView
android:id="@+id/calint_txt_msg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textSize="30sp"
android:text="@string/setup_hint"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>

<de.myProject.FontCheckBox
android:id="@+id/dont_show_hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="-25dp"
android:button="@null"
android:checked="false"
android:drawableLeft="@drawable/my_checkbox_button"
android:drawablePadding="50dp"
android:text="@string/show_hint"
android:textSize="22sp"
/>


<de.myProject.util.FontButton
android:id="@+id/start_but_calibrate"
style="@style/myButton"
android:layout_gravity="center"
android:onClick="onFinishClick"
android:text="@string/ready" />
</LinearLayout>


SetupHintActivity.java



public class SetupHintActivity extends Activity{

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setup_hint);
}

public void onFinishClick(View view) {
CheckBox cb = (CheckBox) findViewById(R.id.dont_show_hint);
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
Editor editor = sharedPref.edit();
editor.putBoolean("dont_show_hint", cb.isChecked());
editor.apply();

finish();
}
}


my_checkbox_button.xml



<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@drawable/my_button_checked" android:state_checked="true"/>
<item android:drawable="@drawable/my_button_unchecked" android:state_checked="false"/>
<item android:drawable="@drawable/my_button_unchecked"/>

</selector>

0 comments:

Post a Comment