gpt4 book ai didi

java - 如何从另一个类获取字符串? - 安卓

转载 作者:行者123 更新时间:2023-12-01 11:52:10 26 4
gpt4 key购买 nike

我有个问题要问你们。我有两个类:

TelaCadastroRestauranteDAO.java - 它不会扩展 Activity

TelaCadastroRestaurante.java - 它确实扩展了 Activity

在我的第一个类TelaCadastroRestauranteDAO.java中,我有一个字符串restauranteParseIdString,它有一个值。我想将此字符串传递给另一个类 TelaCadastroRestaurante.java

我无法使用 Intent 做到这一点,因为我的 ..DAO 类不扩展 Activity,所以我无法导入 Intent(至少,我认为这是问题所在)

<小时/>
public class TelaCadastroRestauranteDAO {

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

...

}

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

最佳答案

因为 restauranteParseIdStringstatic 字段,因此要在其他类中访问它,请使用类名,例如:

String strDAO=TelaCadastroRestauranteDAO.restauranteParseIdString;

并将 restauranteParseIdString 声明为 public 以在其他类中访问:

public static String restauranteParseIdString = restauranteParse.getObjectId();

关于java - 如何从另一个类获取字符串? - 安卓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28710845/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com