如何创建下拉列表?

新手上路,请多包涵

如何创建下拉列表?我已经尝试过 ScrollView 但这并不是我所需要的。

原文由 user1820528 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 440
1 个回答

要将您的列表动态添加到微调器,就像从 web 服务中添加 ArrayList 中的项目并将其加载到微调器

<androidx.appcompat.widget.AppCompatSpinner
    android:id="@+id/catNameSpinner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:spinnerMode="dropdown"
    />

    spinner = findViewById(R.id.catNameSpinner);
    ArrayList<String> cat = new ArrayList<>();
    cat.add("Choose");

    ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>
    (this,android.R.layout.simple_dropdown_item_1line,cat);
    spinner.setAdapter(spinnerAdapter);

原文由 Code with Mohan 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题