【问题标题】:How to make checkboxes work in a live wallpaper Android app?如何使复选框在动态壁纸 Android 应用程序中工作?
【发布时间】:2023-03-13 08:18:01
【问题描述】:

我的动态壁纸设置中有三个复选框,我需要弄清楚如何使它们工作,例如,我希望复选框 1 执行代码 1,复选框 2 执行代码 2,最后一个复选框执行代码 3:

代码1:

private void incrementCounter() {


        if (mImagesArrayIndex >= mImagesArray.length-10) {
            mImagesArrayIndex = mImagesArray.length-10;}
            if (mImagesArrayIndex <10) {
                mImagesArrayIndex = 10;

代码2:

private void incrementCounter() {


        if (mImagesArrayIndex >= mImagesArray.length-20) {
            mImagesArrayIndex = 0;}
            if (mImagesArrayIndex <0) {
                mImagesArrayIndex = mImagesArray.length-20;

            }       

            }   

代码3:

 mImagesArrayIndex++;

code3(进入code1和code2),code1,2,3都在CustomWallpaper.java 就是这样,我已经设置好我的设置布局了,看起来是这样的:

【问题讨论】:

  • @DSS 谢谢您,先生,但这并不是我想要的。我找到了一个解决方案,我不知道这是否是正确的方法,但它可以完成工作,代码位于主问题线程中,仅供那些寻求相同答案的人使用,快乐编码^^

标签: android eclipse checkbox settings live-wallpaper


【解决方案1】:

解决方案:

public void run() {

            SharedPreferences myPref = PreferenceManager.getDefaultSharedPreferences( CustomWallpaper.this);
            try {
                while (true) {
                    drawFrame();

                    if (myPref.getBoolean("lwp_o_scroll_lock_key",true)) 
                    incrementCounter1();
                    else 
                        incrementCounter2();
                    if (myPref.getBoolean("lwp_auto_animation_key",true))
                        mImagesArrayIndex++;
                    else
                        //
                //  if (myPref.getBoolean("lwp_auto_animation_key",true))
                        //incrementCounter2();

                    Thread.sleep(SeekBarPreference.mCurrentValue);
                }
            } catch (Exception e) {
                //
            }
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-16
    • 2012-01-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多