相关疑难解决方法(0)

由于没有窗口焦点而取消事件:MotionEvent

故事是这样的:

我正在尝试在 Android Studio 中构建一个猜谜游戏。用户必须猜测 0 到 1000 之间的数字。每次用户猜测时,计算机都会告诉您猜测的数字是小于实际数字(冷)还是大于实际数字(热)。我决定让用户在 editTextView 中输入他的猜测。我将一个onFocus事件侦听器绑定到 editTextView,以便当用户按 Enter 键或点击其他位置时,它会将猜测提交给计算机。我在模拟器中运行了代码,并从控制台收到了一些消息,内容类似于以下内容:

W/ViewRootImpl: Cancelling event due to no window focus: MotionEvent { action=ACTION_CANCEL, actionButton=0, id[0]=0, x[0]=605.52246, y[0]=969.4336, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=238238, downTime=235422, deviceId=0, source=0x1002 }

public class GameActivity extends AppCompatActivity implements View.OnFocusChangeListener {
    public final int MAXNUMBER = 1000;
    private int theAnswer; // stores the number the user has to guess
    public int guesses = 0;
    public EditText userGuess;
    public TextView hotOrCold; …
Run Code Online (Sandbox Code Playgroud)

android android-studio

5
推荐指数
1
解决办法
6869
查看次数

标签 统计

android ×1

android-studio ×1