gpt4 book ai didi

java - 微调器无需等待查看器的选择即可加载 Intent

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

当查看器从微调器中选择一个项目时,它应该启动一个新的 Intent 。

但应用程序会自动转到 Intent ,而无需等待选择。我认为 onNothingSelected 应该将应用程序保持在当前 Activity 上,直到用户做出选择。我该如何解决这个问题?

areaspinner.setOnItemSelectedListener(new OnItemSelectedListener() {

public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
int item = areaspinner.getSelectedItemPosition();

Bundle bundle = new Bundle();
bundle.putInt("selection", item);

Intent myIntent = new Intent(patriosar.this, ShowXMLPAR.class);
myIntent.putExtras(bundle);
startActivityForResult(myIntent, 0);




}

public void onNothingSelected(AdapterView<?> parent) {
}

最佳答案

尝试这样做

private boolean mFirstSelect = true; //make this a field

areaspinner.setOnItemSelectedListener(new OnItemSelectedListener() {

public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
if (mFirstSelect)
{
mFirstSelect = false;
return;
}
int item = areaspinner.getSelectedItemPosition();

Bundle bundle = new Bundle();
bundle.putInt("selection", item);

Intent myIntent = new Intent(patriosar.this, ShowXMLPAR.class);
myIntent.putExtras(bundle);
startActivityForResult(myIntent, 0);




}

public void onNothingSelected(AdapterView<?> parent) {
}

当您设置值时,您选择的监听器将被触发。这将防止这种情况发生

关于java - 微调器无需等待查看器的选择即可加载 Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6462705/

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