gpt4 book ai didi

java - 如何基于Spinner设置TextView的文字?

转载 作者:行者123 更新时间:2023-11-30 02:16:02 25 4
gpt4 key购买 nike

我的应用程序有 TextView 和 Spinner。微调器包含 2 个项目(A 和 B)。如何根据 Spinner 的选择设置 TextView 的文本?所有这些都必须在一项 Activity 中发生。

if(categoryType.getSelectedItem() == A){
taxFee.setText("Total tax fee:RM" + foodFee);
}else{
taxFee.setText("Total tax fee:RM" + groceryFee);
}

我试过上面的代码,它没有显示我想要的结果。它总是显示这条语句 taxFee.setText("Total tax fee:RM"+ foodFee) 即使我选择了其他类别。

最佳答案

这取决于您的要求,您可以使用位置尝试这种方法:

categoryType.setOnItemSelectedListener(new OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int position, long id) {
if(position == 0)
{
taxFee.setText("Total tax fee:RM" + foodFee);
}else{
taxFee.setText("Total tax fee:RM" + groceryFee);
}

}

@Override
public void onNothingSelected(AdapterView<?> arg0) {
//something
}

});

关于java - 如何基于Spinner设置TextView的文字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29325419/

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