1

Estou tentando cadastrar valores no banco de dados em Kotlin vindo do SeekBar, do DatePicker, Radio Group, vou por partes

no meu CadastroScrolling.kt

consigo jogar a vizualização da idade

// definindo SeekBar
        seekbarIdade = findViewById<SeekBar>(R.id.seekBar_Idade_Pessoa)
        // perform seek bar change listener event used for getting the progress value



        seekbarIdade.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {

             // Methods para tempo de exucção do seekBar

            override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean)
            {
                try
                {
                  var  txtIdade : TextView = findViewById(R.id.text_idade)
                  var  seekBarTest : SeekBar = findViewById(R.id.seekBar_Idade_Pessoa)
                        seekBarTest.isClickable.rangeTo(true).toString()
                    var idadeTest =    txtIdade.setText((progress + 10).toString()+" anos").toString()


                }catch(e: Exception)
                {

                }
            }

            override fun onStartTrackingTouch(seekBar: SeekBar) {/* TODO Auto-generated method stub*/}

            override fun onStopTrackingTouch(seekBar: SeekBar) {
               Toast.makeText(
                    this@CadastroScrollingActivity, "A idade definida é de " + seekbarIdade.progress + " anos",
                    Toast.LENGTH_SHORT
                ).show()
            }

        })



// radio Group 

 // Definir Radio group em grupo e selecionar a escolha feita pelo usuario
        val radioGroup = findViewById<RadioGroup>(R.id.radioGroup_sexo_Pessoa)
        radioGroup.setOnCheckedChangeListener { group, checkedId ->
            var sexo = "Sexo: "
            sexo += if (R.id.radio_feminino_Pessoa == checkedId) "Feminino" else "Masculino"
            Toast.makeText(applicationContext, sexo + " Selecionado",    Toast.LENGTH_LONG).show()
        }



// datePicker

    // definir as datas
        val c = Calendar.getInstance()
        val year = c.get(Calendar.YEAR)
        val month = c.get(Calendar.MONTH)
        val day = c.get(Calendar.DAY_OF_MONTH)

        //chamada da do method datePicker e d Dialog e exbibir no TextView

        calendar_Pessoa.setOnClickListener { 
            val datePD = DatePickerDialog(this, DatePickerDialog.OnDateSetListener { view, mYear, mMonth, mDay ->
                val txt = findViewById<TextView>(R.id.calendar_Pessoa)

                txt.text = (getString(R.string.seu_dt_nas)+(if (mDay < 10 ) "0"+mDay else mDay) + "/" + (if (mMonth < 10 ) "0"+(mMonth+1) else (mMonth+1))
                        + "/" +  mYear)
            },year, month,day )
            datePD.show()
        }


// pegei os ddados so para mascar  nas views agora o metodo de salvar 

private  fun salvar()
    {


        val nome = edit_nome_Pessoa.text.toString()


        val seekTestBar = seekbarIdade.text_idade
        val idade = seekBar_Idade_Pessoa.text.toString()

       // val sexo = (if(radio_feminino_Pessoa.isSelected) "Feminino" else "Masculino")
        val sexo_Id = findViewById<RadioGroup>(R.id.radioGroup_sexo_Pessoa)
        val sexo = sexo_Id.setOnCheckedChangeListener{ group, checkedId ->
            if (R.id.radio_feminino_Pessoa == checkedId) "Feminino" else "Masculino"}.toString()


        //val dt_nasc = calendar_Pessoa.text.toString()

        val dt_nasc = findViewById<TextView>(R.id.calendar_Pessoa).text.toString()
        val rg = edit_rg_Pessoa.text.toString().toInt()
        val cpf =  edit_cpf_Pessoa.text.toString().toInt()
        val rua = edit_rua_Pessoa.text.toString()
        val num_casa = editNumeroCasa_Pessoa.text.toString().toInt()
        val bairro = edit_bairro_Pessoa.text.toString()
        val complemento = edit_comeplemento_Pessoa.text.toString()
        val cep = edit_cep_Pessoa.text.toString().toInt()
        val cidade = edit_cidade_Pessoa.text.toString()
        val estado = edit_uf_Pessoa.text.toString()
        val telefone = edit_telefone_Pessoa.text.toString().toInt()
        val local_estudo = edit_escola_Pessoa.text.toString()
        val nome_mae = edit_mae_Pessoa.text.toString()
        val nome_pai = edit_pai_Pessoa.text.toString()
        val resposavel = edit_resp_Pessoa.text.toString()
        val rg_resp = edit_rg_resp_Pessoa.text.toString().toInt()
        val cpf_resp = edit_cpf_resp_Pessoa.text.toString().toInt()
        val telefone_resp = edit_tel_resp_Pessoa.text.toString().toInt()

        mRegraNegocio_Pessoa.inserir_Pessoa_Businnes(nome,idade,sexo,dt_nasc ,rg,cpf
            ,rua,num_casa,bairro,complemento,cep,cidade,estado
            ,telefone,local_estudo,nome_mae,nome_pai
            ,resposavel,rg_resp,cpf_resp,telefone_resp)
        finish()
    }

2 Respostas 2

0

"Estou tentando cadastrar valores no banco de dados"

Você pode usar Shared Preferences para dados simples e em pequena quantidade.

Ex.: Persistindo dados simples com SharedPreferences

Caso precise salvar uma qrande quantidade de dados, use o SQLiteOpenHelper.

Ex.: Android SQLite Database Tutorial

1
  • obrigado, consegui aqui
    – joannes
    3/04/2019 às 13:03
0

Vlw Pessoa resolvi assim limpei cache, deletei o banco,

adicionei isso no onclick

if (v.id == R.id.edit_calendar_Pessoa) {

        // definir as datas
        val c = Calendar.getInstance()
        val year = c.get(Calendar.YEAR)
        val month = c.get(Calendar.MONTH)
        val day = c.get(Calendar.DAY_OF_MONTH)

        //chamada da do method datePicker e d Dialog e exbibir no TextView
        cal_DatePcker_Pessoa.setOnClickListener {
            val datePD = DatePickerDialog(this, DatePickerDialog.OnDateSetListener { view, mYear, mMonth, mDay ->
                val txt = findViewById<TextView>(R.id.edit_calendar_Pessoa)

                txt.text = (getString(R.string.seu_dt_nas) + (if (mDay < 10) "0" + mDay else mDay) + "/" + (if (mMonth >= 10) mMonth + 1 else "0" + (mMonth + 1)) + "/" + mYear)
            }, year, month, day)
            datePD.show()

        }


    }

e na funcao salvar val dt_nasc = edit_calendar_Pessoa.text.toString()

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .