How to insert a data in your respective Acitivity via Sqlite

Asked

Viewed 29 times

2

Guys I’m making an app on android and inside it has a listiView fixed sent by a string array for example

 String[] servicos = {"Eletricista", "Pedreiro", "Pintor", "Encanador", "Arquiteto", "Engenheiro", "Marcineiro", "Serralheiro"};

In my application I would like the user who works within your respective area to register and be added within your area, I already have the ready form

example of the situation -> an electrician register and his name is played directly on Activity electrician.

How do I make for the sqlite take the dice and play inside their respective Activity.

The project is of the course . I’m sorry if I said something stupid android

1 answer

2


does several else if or switch case who sent it to their respective Act, in this example I suppose that the register is being made in the MainActivity:

Intent it;
switch(tipo) {
    case "encanador": 
        it = new Intent(MainActivity.this, Encanador.class);
        startActivity(it);
        break;
    case "eletricista":
        it = new Intent(MainActivity.this, Eletricista.class);
        startActivity(it);
        break;
}

Serves?

I know there’s a possibility of using a Class.forName(tipo) instead of using Classe.class, being like a String, but I don’t know how to use

Edit:

Complementing with the @ramaral response:

try {
    Class classe = Class.forName("nome.do.pacote." + classe);
    startActivity(new Intent(MainActivity.this, classe));
} catch (ClassNotFoundException e) {
    e.printStackTrace();
}

Being classe the variable registered in the bank

Remembering that the name of the classes must be equal to those registered

  • To use Class.forName(tipo) do so: try {Class classe = Class.forName("NomeDaPackage.NomeDaActiviy");startActivity(new Intent(MainActivity.this, classe));} catch (ClassNotFoundException e) {e.printStackTrace();}. However, to avoid the switch/case, the array must have the name of the corresponding Activity class.

  • Supplemented answer, did not work with me because I did not put the package name as well

  • If the question has been answered, close it, otherwise state your doubts please

Browser other questions tagged

You are not signed in. Login or sign up in order to post.