문제

I've following problem: I've create custom Android class for CheckedTextView:

public class CustomCheckedTextView extends CheckedTextView {
    public CustomCheckedTextView(Context context) {
        super(context);
                this.setOnClickListener (new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        ((CheckedTextView) v) .toggle();
                        if (isChecked()){
                            setBackgroundColor(Color.GREEN);
                        } else {
                            setBackgroundColor(Color.RED);
                        }
                        }

            }) ;
        }
}

And use it in main activity as following:

 LinearLayout llayout = (LinearLayout) findViewById(R.id.linearLayout1);
 final CustomCheckedTextView checkedTV = new CustomCheckedTextView(this);
 llayout.addView(checkedTV)

So I can tap on CustomCheckedTextView and background will be Green. But when I rotate phone background become white again. Why it's happens?

도움이 되었습니까?

해결책 2

Add this to your AndroidManifest.xml file

android:configChanges="orientation"

다른 팁

Do not use configChanges for this. Having an understanding of why it happens and how to save state is very important. Please read the documentation on this topic.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top