程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> viewflipper-android ViewFlipper管理的子頁面中Button設置setEnabled(false)後執行無效,在線急等

viewflipper-android ViewFlipper管理的子頁面中Button設置setEnabled(false)後執行無效,在線急等

編輯:編程綜合問答
android ViewFlipper管理的子頁面中Button設置setEnabled(false)後執行無效,在線急等

android FrameLayout布局中ViewFlipper管理的子頁面中添加添加控件Button、SeekBar等控件,代碼動態設置這些控件為不可用setEnabled(false) 代碼執行後無效,控件還是可以繼續使用,求高手解答。。。在線等。。

如果對activity中的控件 該控件未在ViewFlipper管理的子頁面中,如對Button設置 setEnabled(false)後 該代碼執行後控件被禁用。

代碼如下

public void onLock(View v){
        if (v.getId() == R.id.BntLock){
            bIsLocked = !bIsLocked;
        }

        View view = LayoutInflater.from(this).inflate(R.layout.tab3, null);
        if (bIsLocked){
            ((ImageView)findViewById(R.id.lock)).setImageDrawable(getResources().getDrawable(R.drawable.icon_lock_small));//這個是Activity上的ImageView  對這個控件進行設置後,直接結果OK
            ((Button)findViewById(R.id.BntLock)).setBackground(getResources().getDrawable(R.drawable.icon_lock_big));//這個是Activity上的Button  對這個控件進行設置後,直接結果OK


            //以下5個Button是在子頁面上的控件,設置後代碼執行後  Button還是繼續能用
            ((Button)view.findViewById(R.id.BntTab3Fun01)).setEnabled(false);
            ((Button)view.findViewById(R.id.BntTab3Fun01)).setEnabled(false);
            ((Button)view.findViewById(R.id.BntTab3Fun02)).setEnabled(false);
            ((Button)view.findViewById(R.id.BntTab3Fun03)).setEnabled(false);
            ((Button)view.findViewById(R.id.BntTab3Fun04)).setEnabled(false);
            ((Button)view.findViewById(R.id.BntTab3Fun05)).setEnabled(false);

        }else {

((ImageView)findViewById(R.id.lock)).setImageDrawable(getResources().getDrawable(R.drawable.icon_unlock_small));//同上
            ((Button)findViewById(R.id.BntLock)).setBackground(getResources().getDrawable(R.drawable.icon_unlock_big));//同上

            ((Button)view.findViewById(R.id.BntTab3Fun01)).setEnabled(true);
            ((Button)view.findViewById(R.id.BntTab3Fun02)).setEnabled(true);
            ((Button)view.findViewById(R.id.BntTab3Fun03)).setEnabled(true);
            ((Button)view.findViewById(R.id.BntTab3Fun04)).setEnabled(true);
            ((Button)view.findViewById(R.id.BntTab3Fun05)).setEnabled(true);
        }
    }

最佳回答:


大概試了一下,有效,也使用的FrameLayout,我看你這個lock方法,view是重新inflate的,如果是你已經添加過,這個方法中的View沒有重新添加,自然沒有效果,不知道這個方法調用的場景是如何的,再仔細看看。不知道能不能幫上你的忙,你比較一下有什麼不一樣的吧

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

    mActivity = this;
    viewFlipper = (ViewFlipper) findViewById(R.id.viewflipper);
    gestureDetector = new GestureDetector(this);

    for (int i = 0; i < 10; i++) {
        View view = LayoutInflater.from(this).inflate(R.layout.item, null);
        Button btnButton = (Button) view.findViewById(R.id.btn);
        btnButton.setText("第" + i + "個");
        btnButton.setEnabled(false);
        btnButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(ViewFlipperActivity.this, "Enable=true",
                        Toast.LENGTH_SHORT).show();
            }
        });
        viewFlipper.addView(view, new LayoutParams(
                LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    }
}
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved