首先,我是android开发的新手。我正在构建一个小型应用程序,它的 UI 中包含一个微调器,该应用程序具有四个数字的预定义集合(数组),我正在使用ArrayAdapter该值从资源文件中将值提供给微调器。
微调器工作正常,用户可以选择值。但我也希望用户能够在他们希望输入新值时输入新值。我该怎么做?
Activity 的 onCreate 方法中的代码:
Spinner spinner = (Spinner) findViewById(R.id.spinner);
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.points_preset, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new SpinnerActivity());
SpinnerActivity 类的代码:
更新以包括输入对话框:
public class SpinnerActivity extends Activity implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent, final View view,
int pos, long id) …Run Code Online (Sandbox Code Playgroud) 我正在尝试将一个空的ListBox添加到我的Razor视图页面来存储运行时值.但它给了我一个错误信息说There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'myListBox'.我知道有这样的viewdata.但是,当我使用文本框执行相同操作时,它可以正常工作.
@Html.TextBox("myTextBox")//works alright, displays a textbox
@Html.ListBox("myListBox") // gives error
Run Code Online (Sandbox Code Playgroud)
如何显示一个空的列表框以及为什么上述方法适用于文本框而不是列表框?