Java Android:启用/禁用按钮

Java Android:启用/禁用按钮,java,android,button,Java,Android,Button,我想知道当用户在设置为false后满足特定条件(即高度和宽度大于拼板尺寸的1)时,如何启用按钮 因为,根据我的以下代码,该按钮在虚拟仿真器中保持禁用状态: import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.Menu; import android.view.MenuItem; import and

我想知道当用户在设置为false后满足特定条件(即高度和宽度大于拼板尺寸的1)时,如何启用按钮

因为,根据我的以下代码,该按钮在虚拟仿真器中保持禁用状态:

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

// Class used to retrieve user-input values in order to create the puzzle board based on its
// dimensions as shown in the SecondActivity class.
public class FirstActivity extends AppCompatActivity {
// Initializes fields.
    private EditText etHeight, etWidth;
    private int height, width;
    private Button instructions, play;

    // Main method.
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Instantiates the following variables by reference ID.
        instructions = (Button)findViewById(R.id.instructionsButton);
        play = (Button)findViewById(R.id.playButton);
        play.setEnabled(false);

        instructions.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(FirstActivity.this, PopUpActivity.class);
                startActivity(i);
            }
        });

        play.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // Instantiates the components of a dimension with Android's interfaces.
                etHeight = (EditText)findViewById(R.id.enterHeight);
                String ht = etHeight.getText().toString();

                // Convert to other data types accordingly.
                height = Integer.parseInt(ht);

                etWidth = (EditText)findViewById(R.id.enterWidth);
                String wh = etWidth.getText().toString();
                width = Integer.parseInt(wh);

                if (height > 1 && width > 1) {
                    play.setEnabled(true);
                }

                Intent i = new Intent(FirstActivity.this, SecondActivity.class);
                // Compile data to the Bundle interface.
                i.putExtra("height", height);
                i.putExtra("width", width);
                //v.setEnabled(true);
                startActivity(i);
            }
        });
    }

谢谢

当文本满足某些条件时,只需在编辑文本的ContextChanged方法中将set enabled设置为true。

您已经在此处禁用了按钮:
play.setEnabled(false)你的问题是什么?你已经做了,只需要验证用户输入的拼图大小。。。带有regex???@dpark14的微调器或文本视图用户填充宽度和高度EditText后是否要启用播放按钮?是,启用它。对不起,不清楚;我很忙,不管高度/宽度是否大于1,您都将开始一项新活动-因此您无论如何不能使用启用按钮。。。重点是什么?非常感谢!我发现TextWatcher界面在我的程序中绝对适用。