我有点迷茫,创建一个数据库,用户必须在其中保存研究结果,在该数据库中,他将从各种微件中选择数据,例如微调器或RG。对我来说,如何编码类型为Int或String的变量不是问题,但是对于Spinner number picker和RG而言。有人可以理顺我吗?

主要 Activity

    Package com.example.apkadlapacjenta

import android.os.Bundle
import com.google.android.material.snackbar.Snackbar
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.RecyclerView
import com.google.firebase.database.DatabaseReference
import com.google.firebase.database.FirebaseDatabase

import kotlinx.android.synthetic.main.activity_historia_pomiarow.*


class HistoriaPomiarow : AppCompatActivity() {

    var listaWynikow = ArrayList<FIrebaseVal>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_historia_pomiarow)
        setSupportActionBar(toolbar)

        //Wczytujemy baze danych
        LoadQuery("%")

        supportActionBar?.setDisplayHomeAsUpEnabled(true)
    }
    override fun onResume() {
        super.onResume()
        LoadQuery("%")
    }

    private fun LoadQuery(title:String){
        val dbManager = DbMenager(this)
        val projections = arrayOf("Id", "Stezenie", "Zegar","Data","Posilek","Stres","Samopoczucie","Hiperglikemia","Insulina")
        val cursor =
            dbManager.Query(projections, "Title like?", selectionArgs   , "Title")
        listaWynikow.clear()
        if (cursor.moveToFirst()) {
            do {
                ***val ID = cursor.getInt(cursor.getColumnIndex("Id"))      ---> HERE i have problem
                val Stezenie = cursor.getInt(cursor.getColumnIndex("Stezenie")) ---> NumberPicker
                val Zegar = cursor.getString(cursor.getColumnIndex("Zegar"))
                val Data =cursor.getString(cursor.getColumnIndex("Data"))
                val Posilek = cursor.getString(cursor.getColumnIndex("Posilek")) -----> RB
                val Stres = cursor.getString(cursor.getColumnIndex("Stres"))
                val Samopoczucie = cursor.getString(cursor.getColumnIndex("Samopoczucie"))   --->SPINNER
                val Hiperglikemia = cursor.getString(cursor.getColumnIndex("Hiperglikemia"))--->SPINNER
                val Insulina = cursor.getInt(cursor.getColumnIndex("Insulina"))       --->SPINNER
                **listaWynikow.add(Note(ID, Stezenie, Zegar,Data,Posilek,Stres,Samopoczucie,Hiperglikemia,Insulina))
            } while (cursor.moveToNext())*****
        }
    }

}

“---> Spinner,Numberpicker,RG”等不是代码

DateBase Menager
    package com.example.apkadlapacjenta

import android.content.ContentValues
import android.content.Context
import android.database.Cursor
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import android.database.sqlite.SQLiteQueryBuilder
import android.widget.RadioGroup
import android.widget.Toast

class DatebaseMenagerPomiary {

    //Database name
    var dbName = "Historia Pomiarów"
    //table name
    var dbTable = "Wyniki"
    //kolumny
    var colID = "Id"
    var colStezenie = "Stezenie"
    var colZegar = "Zegar"
    var colData = "Data"
    var colPosilek = "Posilek"
    var colStres = "Stres"
    var colSamopoczucie = "Samopoczucie"
    var colHiperglikemia = "Hiperglikemia"
    var colInsulina = "Insulina"

    //wersja
    var dbVersion = 1

    //Tworzymy tabele
    val sqlCreateTable =
        "CREATE TABLE$dbTable($colID INTEGER PRIMARY KEY, $colStezenie NumberPicker, $colZegar TEXT, $colData TEXT, $colPosilek RADIO GROUP, $colStres SPINNER,$colSamopoczucie SPINNER, $colHiperglikemia SPINNER, $colInsulina TEXT)"

    var sqlDB: SQLiteDatabase? = null
    constructor(context: Context){
        var db = DatabaseHelperWyniki(context)
        sqlDB = db.writableDatabase
    }


     inner class DatabaseHelperWyniki : SQLiteOpenHelper {
        var context: Context? = null
         constructor(context: Context) : super(context, dbName, null, dbVersion) {
            this.context = context
        }

        override fun onCreate(db: SQLiteDatabase?) {
            db!!.execSQL(sqlCreateTable)
            Toast.makeText(this.context,"baza danych utworzona...",Toast.LENGTH_SHORT).show()

        }

        override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
            db!!.execSQL("zamknij tabele jeśli nie istnieje" + dbTable)
        }


    }

    fun  insert(values:ContentValues):Long{
        val ID  = sqlDB!!.insert(dbTable,"",values)
        return ID
    }
    fun Query(projection:Array<String>,selection:String,selectionArgs:Array<String>,sorOrder:String): Cursor {

        val qb = SQLiteQueryBuilder();
        qb.tables=dbTable
        val cursor = qb.query(sqlDB,projection,selection,selectionArgs,null,null,sorOrder)
        return cursor
    }

    fun delete(selection: String,selectionArgs: Array<String>):Int{
        val count = sqlDB!!.delete(dbTable,selection,selectionArgs)
        return count
    }

    fun update(values:ContentValues,selection: String,selectionArgs: Array<String>): Int {
        val count = sqlDB!!.update(dbTable,values,selection,selectionArgs)
        return count
    }



}

节点类
NODE CLASS

    package com.example.apkadlapacjenta

import android.provider.MediaStore
import android.widget.NumberPicker
import android.widget.RadioGroup
import android.widget.Spinner

class FIrebaseVal(nodeID: Int, nodeNumberPicker:NumberPicker,nodezegar:String,nodedata:String,nodeposilek:RadioGroup,nodehiperglikemia:Spinner,nodestres:Spinner,nodesamopoczucie:Spinner,nodeinsulina:Int) {
    var nodeID: Int?= nodeID
    var nodeNumberPicker:NumberPicker?= nodeNumberPicker
    var nodezegar:String?=nodezegar
    var nodedata:String?=nodedata
    var nodeposilek:RadioGroup?=nodeposilek
    var nodehiperglikemia:Spinner?=nodehiperglikemia
    var nodestres:Spinner?=nodestres
    var nodesamopoczucie:Spinner?=nodesamopoczucie
    var nodeinsulina:Int?=nodeinsulina
}

我知道该怎么做的其余代码(即适配器和SearchView等各种功能)在Numberpicker,Spinner和RG编码方面需要帮助,因为在该行中:
listaWynikow.add(Note(ID, Stezenie, Zegar,Data,Posilek,Stres,Samopoczucie,Hiperglikemia,Insulina))
            } while (cursor.moveToNext())

我得到一个错误
“公共(public)构造函数string()定义的参数过多”。

最佳答案

节点类的问题在这里,您已经声明了总共9个参数:

class FIrebaseVal(nodeID: Int, nodeNumberPicker:NumberPicker,nodezegar:String,nodedata:String,nodeposilek:RadioGroup,nodehiperglikemia:Spinner,nodestres:Spinner,nodesamopoczucie:Spinner,nodeinsulina:Int)

但是在这里,您传递的10个参数请确认参数值。我不明白变量名。
listaWynikow.add(Note(ID, Stezenie, Zegar,Data,Posilek,Stres,Samopoczucie,Hiperglikemia,Insulina))

10-08 17:26