当前位置: 动力学知识库 > 问答 > 编程问答 >

java - 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();

}

}

}

网友答案:

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();
分享给朋友:
您可能感兴趣的文章:
随机阅读: