Мне было интересно, как включить кнопку, когда пользователь соответствует определенным критериям (то есть высота и ширина больше 1 для размеров головоломки) ПОСЛЕ того, чтобы установить значение false ...Android: Включение/выключение кнопок
Потому что, исходя из моего следующего кода, кнопка остается заблокированной в виртуальном эмуляторе:
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);
}
});
}
Спасибо!
Вы уже отключили свою кнопку здесь: 'play.setEnabled (false);' В чем ваш вопрос? –
Вы уже сделали это, просто нужно проверить вход пользователя для размера головоломки ... прядильный или текстовый вид с регулярным выражением ??? –
@ dpark14 Вы хотите включить кнопку воспроизведения после заполнения пользователем ширины и высоты edittexts? –