lurdes
lurdes

Reputation: 3

How do i get a String from another class? - ANDROID

i got a question for you guys. I have 2 classes:

TelaCadastroRestauranteDAO.java - IT DOES NOT EXTENDS ACTIVITY

and

TelaCadastroRestaurante.java - IT DOES EXTENDS ACTIVITY

In my first class TelaCadastroRestauranteDAO.java, i have a string restauranteParseIdString which it has a value. And i want pass this string to the other class TelaCadastroRestaurante.java.

I couldn't do it with Intent, because my ..DAO class doesn't extends activity, so i can't import Intent (at least, i think that is the problem)


public class TelaCadastroRestauranteDAO {

private static ParseObject restauranteParse;
private static String restauranteParseIdString = restauranteParse.getObjectId();
private static ProgressDialog dialog;
private static AlertDialog.Builder builderaction;

... 

}

and

public class TelaCadastroRestaurante extends Activity {

private Restaurante rest;
private Button proximoButton;
private EditText nomeRestauranteEditText, emailRestauranteEditText, telefoneRestauranteEditText;
private String nomeRestauranteString, emailRestauranteString, telefoneRestauranteString, idRestaurante;
private String voceTemCertezaCadastrarRestaurante = "Você tem certeza que deseja cadastrar o restaurante: ";
private Context contexThisClass = TelaCadastroRestaurante.this;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tela_cadastro_restaurante);

    // i want get the string right here

    if(checkwifi()){
        setUpComponents();
        dealButtons();
    }
}
}

Upvotes: 0

Views: 363

Answers (1)

ρяσѕρєя K
ρяσѕρєя K

Reputation: 132992

Because restauranteParseIdString is static field so to access it in other class use class name like:

String strDAO=TelaCadastroRestauranteDAO.restauranteParseIdString;

and declare restauranteParseIdString as public to access in other classes:

public static String restauranteParseIdString = restauranteParse.getObjectId();

Upvotes: 1

Related Questions