gpt4 book ai didi

java - 如何处理多个微调器所选项目的比较?

转载 作者:行者123 更新时间:2023-12-02 03:51:29 25 4
gpt4 key购买 nike

当两个微调器选择的值彼此相等时,我试图让我的应用程序显示文本或图像。

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Spinner sp1 =(Spinner)findViewById(R.id.sp1);
String txtFromSpinner1 = sp1.getSelectedItem().toString();

Spinner sp2 = (Spinner)findViewById(R.id.sp2);
String txtFromSpinner2 = sp2.getSelectedItem().toString();

if (txtFromSpinner1.equals(1)&& txtFromSpinner2.equals(2)){

TextView textElement = (TextView)findViewById(R.id.txResult);
textElement.setText("3");

}
}
}

最佳答案

试试这个:

Spinner sp1 =(Spinner)findViewById(R.id.sp1);
Spinner sp2 = (Spinner)findViewById(R.id.sp2);
TextView textElement = (TextView)findViewById(R.id.txResult);
Button showResult = (Button)findViewById(R.id.btnShowResult);

showResult.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String txtFromSpinner1 = sp1.getSelectedItem().toString();
String txtFromSpinner2 = sp2.getSelectedItem().toString();

if (txtFromSpinner1.equals("1")&& txtFromSpinner2.equals("2"))
textElement.setText("3");


}
});

关于java - 如何处理多个微调器所选项目的比较?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35836179/

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