Android Studio (Kotlin): собственный класс GridLayout - PullRequest
0 голосов
/ 14 января 2020

Я пытаюсь создать свой собственный LayoutClass, но когда я пытаюсь использовать, все кнопки исчезают. Я создал его с помощью конструктора, и он отлично работает (без собственного класса). (Это должен быть простой калькулятор)

Что я не так делаю?

package calculator

import android.widget.GridLayout
import android.content.Context
import android.util.AttributeSet


import kotlinx.android.synthetic.main.activity_main.view.*

class CalcView(context: Context, attributes: AttributeSet?) : GridLayout(context, attributes), CalcViewInterface {

    override fun onAttachedToWindow() {

        super.onAttachedToWindow()
        CalcController.attach(this)

    }

    override fun onDetachedFromWindow() {
        super.onDetachedFromWindow()
        CalcController.detach()
    }

    override fun setEquation(equation: String) {
        this.grid_main.text_calc.text = equation
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates


    }

    override fun setResult(result: String) {
        this.grid_main.text_calc.text = result
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.

    }

    fun update() {
        grid_main.text_calc.text = "Clicked"
    }


}

и

activity_main. xml

(извините, я не знаю, как включить xml, текст не отображается)

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="myc.calc.mycal.MainActivity"

       calculator.CalcView
       android:id="@+id/grid_main"
       android:layout_width="0dp"
       android:layout_height="0dp"
       android:addStatesFromChildren="true"
       android:background="@color/colorButton"
       app:alignmentMode="alignMargins"
       app:columnCount="4"
       app:layout_constraintBottom_toBottomOf="parent"
       app:layout_constraintEnd_toEndOf="parent"
       app:layout_constraintStart_toStartOf="parent"
       app:layout_constraintTop_toTopOf="parent"
       app:rowCount="7"

       TextView android:id="@+id/text_calc"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:background="@color/colorButton"
       android:gravity="right"
       android:paddingRight="40dp"
       android:paddingTop="20dp"
       android:text="@string/b_0"
       android:textColor="@color/colorFontWhite"
       android:textSize="30sp"
       app:layout_column="0"
       app:layout_columnSpan="4"
       app:layout_gravity="fill"
       app:layout_row="0"

       Button
       android:id="@+id/b_mal"
       android:layout_width="0dp"
       android:layout_height="0dp"
       android:background="@color/colorButton"
       android:text="@string/b_mal"
       android:textColor="@color/colorFontGreen"
       android:textColorHint="@color/colorFontGreen"
       android:textSize="24sp"
       app:layout_column="3"
       app:layout_columnWeight="1"
       app:layout_gravity="fill"
       app:layout_row="3"
       app:layout_rowWeight="1"

        ... more Buttons

        calculator.CalcView
        androidx.constraintlayout.widget.ConstraintLayout

Что я не так делаю? (извините за мой английский sh)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...