введите здесь описание изображения
activity_main.xml
Код: Выделить всё
android:id="@+id/buttonSayHello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Say Hello"
android:onClick="SayHello"
android:layout_marginTop="16dp"
android:layout_gravity="center_horizontal"/>
>
Код: Выделить всё
package com.example.gamin;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
class MainActivity extends AppCompatActivity implements TextWatcher {
EditText nameText;
TextView textGreeting;
Button buttonSayHello;
MainActivity() {
nameText = findViewById(R.id.editTextTextPersonName);
}
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textGreeting = findViewById(R.textView2);
buttonSayHello = findViewById(R.id.button);
nameText.addTextChangedListener(this);
buttonSayHello.setEnabled(false);
}
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
public void afterTextChanged(Editable s) {
buttonSayHello.setEnabled(!nameText.getText().toString().matches(""));
}
public void SayHello(View view)
{
if(!nameText.getText().toString().matches(""))
{
textGreeting.setText("Howdy "+nameText.getText());
}
else
{
textGreeting.setText("Please enter your name");
}
}
}
Произошла ошибка при выполнении com.android.build .gradle.internal.res.ParseLibraryResourcesTask$ParseResourcesRunnable
Не удалось проанализировать XML-файл '/Users/gain/AndroidStudioProjects/Gamin/app/build/intermediates/packaged_res/debug/packageDebugResources/layout/activity_main.xml'
Вызвано: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: произошел сбой при выполнении com.android.build.gradle.internal.res.ParseLibraryResourcesTask$ ParseResourcesRunnable
Подробнее здесь: https://stackoverflow.com/questions/790 ... tionexcept