Android变量检查不起作用

时间:2014-11-04 13:45:57

标签: android variables

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

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) {

            }
        }
    });
}

1 个答案:

答案 0 :(得分:0)

您的支票是通过分配代替比较

if(variable1 == true)

而不是

if(variable1 = true)

你应该养成以另一种方式写它的习惯,这样你就不会犯错误:

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