Пару вопросов:
1 - не получается сделать "общую запись" Про котов и ворон - только разделением через разные TextView, иначе одновременно при нажатии Считаем ворон (или Считаем котястых) плюсует оба счетчика
2 - Хоть и нажимал "Infer Constaints" почему то при нажатии любой из Считаем - Сами кнопки "плавают"
Или это в следующих уроках??
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.pekse.schvoron.MainActivity"
tools:layout_editor_absoluteY="81dp"
tools:layout_editor_absoluteX="0dp">
<Button
android:id="@+id/buttonCrowCounter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="Считаем ворон"
android:layout_marginStart="14dp"
tools:layout_constraintTop_creator="1"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="@+id/buttonCatCounter"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginLeft="14dp" />
<Button
android:id="@+id/buttonCatCounter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="Считаем котястых"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
app:layout_constraintRight_toRightOf="@+id/textView2"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/buttonCrowCounter"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toRightOf="@+id/textView2" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
app:layout_constraintRight_toRightOf="@+id/textView3"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@+id/buttonCatCounter"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toRightOf="@+id/textView3" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@+id/textView2"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent" />
<Button
android:id="@+id/buttonHello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="Поздороваться"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintBottom_creator="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintBottom_creator="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="107dp"
app:layout_constraintTop_toBottomOf="@+id/buttonHello"
tools:layout_constraintLeft_creator="1"
android:layout_marginBottom="107dp"
app:layout_constraintLeft_toLeftOf="parent" />
</android.support.constraint.ConstraintLayout>
package com.example.pekse.schvoron;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private Button mCrowCounterButton;
private Button mCatCounterButton;
private int mCount = 0;
private int mCountCat = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mCatCounterButton = (Button) findViewById(R.id.buttonCatCounter);
mCatCounterButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TextView mInfoTextView = (TextView) findViewById(R.id.textView3);
mInfoTextView.setText("И " + ++mCountCat + " котяр");
}
});
mCrowCounterButton = (Button) findViewById(R.id.buttonCrowCounter);
mCrowCounterButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TextView mInfoTextView = (TextView) findViewById(R.id.textView2);
mInfoTextView.setText("Я насчитал " + ++mCount + " ворон.");
}
});
}
public void onClick(View view) {
TextView helloTextView = (TextView) findViewById(R.id.textView);
helloTextView.setText("Привет катямба :-)");
}
}