我想将一些变量传递给主类,并根据用户在前面的接口中的输入进行一些计算。我尝试过使用 setter 和 getters,但最令人困惑的部分是如何使用这些变量进行计算,而无需在 TextView 中显示它们。
public class Weight extends AppCompatActivity implements View.OnClickListener {
public static AutoCompleteTextView userWeight;
private Button secondPage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_weight);
userWeight =(AutoCompleteTextView) findViewById(R.id.weight);
secondPage = (Button) findViewById(R.id.toHeightPage);
secondPage.setOnClickListener(this);
}
}
private void enterWeight(){
String weight = userWeight.getText().toString().trim();
if(TextUtils.isEmpty(weight)){
Toast.makeText(Weight.this,"Please Enter your weight", Toast.LENGTH_SHORT).show();
return;
}
在这个类中,我想获取权重的值并在主类中使用它,这里是主类代码。
public class Main_Interface extends AppCompatActivity {
public TextView results;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main__interface);
Toolbar toolbar = findViewById(R.id.toolbar1);
setSupportActionBar(toolbar);
results = (TextView)findViewById(R.id.results);
}
public void calculateBMR(){
}
我将使用计算方法来使用应用程序中的所有变量来为我提供结果。
largeQ
幕布斯7119047
相关分类