我如何在微调器中将 2 个位置值显示为默认值

How can i show 2 position value as default in spinner

就像我在 Spinner 中有 10 个值(0-9 个位置)。如果我想在 onCreate() 的微调器中将 2 个位置值显示为默认值怎么办...

正如其他人所指出的,您正在使用 cityArrayList 创建微调器适配器,但您没有向此 ArrayList 添加任何项目。这就是您的微调器为空白的原因。一旦数据可用,您应该刷新适配器。

这就是你应该做的。

protected void onPostExecute(Boolean result) {
    if(result == false)
        Toast.makeText(getApplicationContext(), "Unable to fetch data from server", Toast.LENGTH_LONG).show();
    else {
        adapter.notifyDataSetChanged();
        mySpinner.setSelection(2)
    }
}

从您的 link 查看您的代码,您还没有调用 adapter.notifyDataSetChanged()。请检查一下。你应该在 postExecute() 方法中调用它

另外请使用 .equals() 检查 String 值而不是 ==。那可能是你的问题。

if(strPHPCity.equals("Delhi")) {
    spinnerCity.setSelection(0);
} else if (strPHPCity.equals("Banglore")) {
     spinnerCity.setSelection(1);
}