调用方法后为什么我的变量没有更新?

时间:2018-04-03 21:54:31

标签: android variables methods maps global

AppState

执行的顺序似乎没有像我想要的那样发生。在控制台输出上,在x = 6之前打印x = 0.为什么会这样? Android是否同时运行方法调用?

1 个答案:

答案 0 :(得分:0)

我尝试了你的代码并为我工作,否则为了解决你的问题,你可以试试这个:

something();
Handler handler = new Handler();
final Runnable runnable = new Runnable() {
    public void run() {
        System.out.println(sumX);
    }
};
handler.postDelayed(runnable, 50); //50 millisec (delay)

或(不太清楚)

Sub Mark_cells_in_column()
    Dim FirstAddress As String
    Dim MyArr As Variant
    Dim Rng As Range
    Dim I As Long

    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With

    MyArr = Array("VC")
    With Sheets("Sheet1").Range("A2:d20")
        For I = LBound(MyArr) To UBound(MyArr)
             Set Rng = .Find(What:=MyArr(I), _
                        After:=.Cells(.Cells.Count), _
                        LookIn:=xlFormulas, _
                        LookAt:=xlPart, _
                        SearchOrder:=xlByRows, _
                        SearchDirection:=xlNext, _
                        MatchCase:=False)
            If Not Rng Is Nothing Then
                FirstAddress = Rng.Address
                Do
                    Rng.Interior.ColorIndex = 3
                    Set Rng = .FindNext(Rng)
                Loop While Not Rng Is Nothing And Rng.Address <> FirstAddress
            End If
        Next I
    End With
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
End Sub