В принципе мне нужен TableLayout, который содержит несколько строк, и в каждой строке должен быть другой счетчик (который я могу добавить или вычесть 1, нажав одну из двух кнопок в строке).Множественные и разные счетчики в одном действии
Здесь вы можете увидеть наглядный пример:
content_main.xml
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginTop="55dp">
<TextView
android:text="Pizza Margherita"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView27"
android:layout_weight="10"
android:layout_column="1" />
<Button
android:text="-"
android:layout_height="wrap_content"
android:id="@+id/minusButton"
android:layout_weight="1"
android:layout_column="1"
android:layout_width="50dp" />
<TextView
android:text="0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/result"
android:layout_weight="5"
android:layout_column="1"
android:textAlignment="center" />
<Button
android:text="+"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:id="@+id/plusButton"
android:elevation="0dp"
android:layout_weight="0.5"
android:layout_column="1" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp">
<TextView
android:text="Pizza Salame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView27"
android:layout_weight="10"
android:layout_column="1" />
<Button
android:text="-"
android:layout_height="wrap_content"
android:id="@+id/minusButton2"
android:layout_weight="1"
android:layout_column="1"
android:layout_width="50dp" />
<TextView
android:text="0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/result2"
android:layout_weight="5"
android:layout_column="1"
android:textAlignment="center" />
<Button
android:text="+"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:id="@+id/plusButton2"
android:elevation="0dp"
android:layout_weight="0.5"
android:layout_column="1" />
</TableRow>
</TableLayout>
Я понятия не имею, как работать на MainActivity.java. На днях я попытался реализовать массив (без успеха) и написать отдельный класс для каждого отдельного счетчика (но это слишком избыточно).
Любые советы?
Подсказка: без вас отображается больше кода, здесь не так много. Мы не являемся «видением, но не представляем, пожалуйста, заполните пробел». Кроме того: вы можете указать имена кнопок, которые более отчетливы. Не назовите мелочь кнопки или кнопки, почему бы не назвать их минус-баттон или плюсButton ?! – GhostCat
Да, извините. Моя вина. – Kevin