我有一个对话框出现,用户可以在其中计算他们从每个动作中获得的分数。该对话框基于不是 main_activity 的布局。主要活动是在 onCreate 方法中的 setContentView 中使用的布局。
当我尝试获取值时,我只会得到 null,(因为 EditText 未设置为 contentview 的布局......也许?)
我如何解决这个问题,以便我在“设置”布局中获得 edittext 的值并可以在 MainActivity 中使用该值?
private int teamOnePoints=0;
private int teamTwoPoints=0;
private boolean teamOneField=true;
private int burnedPoints = 1;
private int lyrePoints= 3;
private int oneHandLyrePoints = 5;
private int homeRunPoints=5;
private int revPoints=1;
private String teamOneName = "Lag 1";
private String teamTwoName = "Lag 2";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ToggleButton toggle = (ToggleButton)
findViewById(R.id.field_team_toggle); //activates toggle button
toggle.setOnCheckedChangeListener(new
CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean
isChecked) {
if (isChecked) {
//changes between the teams
teamOneField=false;
} else {
teamOneField=true;
}
}
});
FloatingActionButton fab = findViewById(R.id.points_edit_button);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openDialog();
}
});
}
阿晨1998
相关分类