开发者

how to disable a layout and its contents programatically in android

I have 4 LinearLayouts in a RelativeLayout and I am also using an ImageView. When the ImageView is displayed I want to disa开发者_JAVA百科ble the 4 LinearLayouts and their contents. Each LinearLayout contains 4 buttons. Shown below is my function to disable and enable these layouts. Can someone help me understand why this isn't working?

private void disablelayout(final LinearLayout l1,final LinearLayout l2,final LinearLayout l3,final LinearLayout l4)
    {
        l1.setEnabled(false);
        l2.setEnabled(false);
        l3.setEnabled(false);
        l4.setEnabled(false);

    }
    private void enablelayout(final LinearLayout l1,final LinearLayout l2,final LinearLayout l3,final LinearLayout l4)
    {
        l1.postDelayed(new Runnable(){             
             @Override             
             public void run() {                 
                 l1.setEnabled(true); 
                 l2.setEnabled(true); 
                 l3.setEnabled(true); 
                 l4.setEnabled(true); 
             }         
             }, 3000);
    }


private void enableDisableView(View view, boolean enabled) {
    view.setEnabled(enabled);

    if ( view instanceof ViewGroup ) {
        ViewGroup group = (ViewGroup)view;

        for ( int idx = 0 ; idx < group.getChildCount() ; idx++ ) {
            enableDisableView(group.getChildAt(idx), enabled);
        }
    }
}


Use setVisibility() to either INVISIBLE or GONE.


Use like this:

l1.setVisibility(View.GONE);
l2.setVisibility(View.GONE);
l3.setVisibility(View.GONE);
l4.setVisibility(View.GONE);


Use can use this for hide the whole layout

l1.setVisibility(View.GONE);
l2.setVisibility(View.GONE);
l3.setVisibility(View.GONE);
l4.setVisibility(View.GONE);

whenever you want to display particular layout then you can 

l1.setVisibility(View.VISIBLE);


Set "Clickable" property for all items to false. The method is setClickable(boolean).
After that no one could click it. Also you could look into this question: How to disable an Android button

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜