gpt4 book ai didi

java - 显示两个微调器的输出

转载 作者:行者123 更新时间:2023-12-01 08:54:53 25 4
gpt4 key购买 nike

我正在尝试在 android studio 上制作一个简单的应用程序,它允许我选择两支球队(从旋转器中),然后打印出他们的最终得分或不参加比赛。

我已经能够完成整个设置并正常工作,但是我无法在 TextView 中显示分数。它总是只是说球队没有参加比赛

`public class MainActivity extends AppCompatActivity {
Spinner spinner1, spinner2;
ArrayAdapter<CharSequence> adapter1, adapter2;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
spinner1 = (Spinner) findViewById(R.id.spinner1);
adapter1 = ArrayAdapter.createFromResource(this,R.array.list1,android.R.layout.simple_spinner_item);
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner1.setAdapter(adapter1);
spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
TextView spinner1Text = (TextView) view;

}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}
});
spinner2 = (Spinner) findViewById(R.id.spinner2);
adapter2 = ArrayAdapter.createFromResource(this,R.array.list2,android.R.layout.simple_spinner_item);
adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner2.setAdapter(adapter2);
spinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
TextView spinner1Text = (TextView) view;

}


@Override
public void onNothingSelected(AdapterView<?> parent) {

}
});
final Button button = (Button)findViewById(R.id.Show);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
button.refreshDrawableState();
}
});

TextView score = (TextView) findViewById(R.id.Score);

if (spinner1.getSelectedItem().toString().equals("Patriots")&& spinner2.getSelectedItem().toString().equals("Seahawks")) {
score.setText("Patriots 21, Seahawks 14" + "\n" + "Q1 Patroits 3 Seahawks 0" + "\n" + "Q2 Patroits 3 Seahawks 14" + "\n" + "Q3 Patroits 14 Seahawks 14" + "\n" + "Q4 Patroits 21 Seahawks 14");}

else if (spinner1.getSelectedItem().toString().equals("Falcons")&& spinner2.getSelectedItem().toString().equals("Raiders")){
score.setText("Falcons 3, Raiders 18" + "\n" + "Q1 Falcons 0 Raider 0" + "\n" + "Q2 Falcons 0 Raider 13" + "\n" + "Q3 Falcons 0 Raider 15" + "\n" + "Q4 Falcons 0 Raider 18");}

else if (spinner1.getSelectedItem().toString().equals("Eagles")&& spinner2.getSelectedItem().toString().equals("Cowboys")){
score.setText("Eagles 42, Cowboys 38" + "\n" + "Q1 Eagles 3 Cowboys 21" + "\n" + "Q2 Eagles 21 Cowboys 29" + "\n" + "Q3 Eagles 28 Cowboys 35" + "\n" + "Q4 Eagles 42 Cowboys 38");}

else if (spinner1.getSelectedItem().toString().equals("Bears")&& spinner2.getSelectedItem().toString().equals("Redskins")){
score.setText("Bears 20, Redskins 0" + "\n" + "Q1 Bears 3 Redskins 0" + "\n" + "Q2 Bears 3 Redskins 0" + "\n" + "Q3 Bears 17 Redskins 0" + "\n" + "Q4 Bears 20 Redskins 0");}

else score.setText("Those two teams did not play each other");




}
<resources>
<string name="app_name">NFL Scorer Application</string>
<string name="first_team">Please select the first team</string>
<string name="second_team">Please select the second team</string>
<string-array name="list1">

<item></item>
<item>Patriots</item>
<item>Falcons</item>
<item>Eagles</item>
<item>Bears</item>
</string-array>

<string-array name="list2">
<item></item>
<item>Seahawks</item>
<item>Raiders</item>
<item>Cowboys</item>
<item>Redskins</item>
</string-array>
</resources>

最佳答案

谢谢 Pavneet Singh,我只需要把 if-else 移到监听器

关于java - 显示两个微调器的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42095850/

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