Android变量检查不起作用

Android变量检查不起作用,android,variables,Android,Variables,我想更改按钮的SetCompoundDrawableSwithinInstincBounds属性。它应显示不同的图标,具体取决于计数器通知变量。例如,日志显示了这一点,但没有任何变化。我做错了什么 11-04 14:40:57.728 20765-20765/ADebugTag﹕ Test1: 2 11-04 14:40:57.728 20765-20765/ADebugTag﹕ Test2: true 11-04 14:40:57.728 20765-20765/ADebugTag﹕ T

我想更改按钮的SetCompoundDrawableSwithinInstincBounds属性。它应显示不同的图标,具体取决于计数器通知变量。例如,日志显示了这一点,但没有任何变化。我做错了什么

11-04 14:40:57.728  20765-20765/ADebugTag﹕ Test1: 2
11-04 14:40:57.728  20765-20765/ADebugTag﹕ Test2: true
11-04 14:40:57.728  20765-20765/ADebugTag﹕ Test3: false
11-04 14:40:57.728  20765-20765/ADebugTag﹕ Test4: false



        public void doNotification() {
    runOnUiThread(new Runnable() {
        public void run() {
            try {
                final Button notification_text = (Button) findViewById(R.id.notification_text);
                notification_text.setVisibility(View.VISIBLE);

                Log.d("ADebugTag", "Test1: " + counter_notification);
                Log.d("ADebugTag", "Test2: " + variable1);
                Log.d("ADebugTag", "Test3: " + variable2);
                Log.d("ADebugTag", "Test4: " + variable3);

                if(counter_notification==1){
                if(variable1=true){
                    benachrichtigung_text.setCompoundDrawablesWithIntrinsicBounds( R.drawable.icon_1, 0, 0, 0);
                } if(variable2=true){
                    benachrichtigung_text.setCompoundDrawablesWithIntrinsicBounds( R.drawable.icon_2, 0, 0, 0);
                } if (variable3=true){
                    benachrichtigung_text.setCompoundDrawablesWithIntrinsicBounds( R.drawable.icon_3, 0, 0, 0);
                }
                } if(counter_notification==2){
                if(variable1=true){
                    benachrichtigung_text.setCompoundDrawablesWithIntrinsicBounds( R.drawable.icon_1_1, 0, 0, 0);
                } if(variable2=true){
                    benachrichtigung_text.setCompoundDrawablesWithIntrinsicBounds( R.drawable.icon_2_1, 0, 0, 0);
                } if (variable3=true){
                    benachrichtigung_text.setCompoundDrawablesWithIntrinsicBounds( R.drawable.icon_3_1, 0, 0, 0);
                }
                } if(counter_notification==3){
                if(variable1=true){
                    benachrichtigung_text.setCompoundDrawablesWithIntrinsicBounds( R.drawable.icon_1_2, 0, 0, 0);
                } if(variable2=true){
                    benachrichtigung_text.setCompoundDrawablesWithIntrinsicBounds( R.drawable.icon_2_2, 0, 0, 0);
                } if (variable3=true){
                    benachrichtigung_text.setCompoundDrawablesWithIntrinsicBounds( R.drawable.icon_3_2, 0, 0, 0);
                }
                }
            }catch (Exception e) {

            }
        }
    });
}

您的支票是用转让而不是比较方式进行的

if(variable1 == true)
而不是

if(variable1 = true)
你应该养成用另一种方式写的习惯,这样你就不会犯你犯的错误:

if(true == variable1)//can't forget one of the '=' because it won't compile

请正确缩进代码,如果(variable3=true)应该是if(variable3==true)或if(variable3)