微调器添加项目
我一直在遵循将微调器项目添加到应用程序的微调器控件的教程。进入应用程序时,它强制关闭,当我注释代码时,它工作正常,但不会填充微调器控件。我对 Android 世界相当陌生。
这是我的代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Intent intent = getIntent();
Spinner spinner = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.spinnerss, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
I have been following the tutorial for adding spinner items to a spinner control for an app. When going into the app, it force closes, and when I comment the code, it works fine, but does not fill the spinner control. Im rather new to the Android world.
Here is my code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Intent intent = getIntent();
Spinner spinner = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.spinnerss, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因为你没有在sure.onCreate之后添加下面的行。
Because you have not add after sure.onCreate put below line.
我确信可能由于以下原因而出现问题:
或者:
您实际上定义了“spinnerss”吗?
请检查这两行,并且应该输入 Logcat 输出,以便我们可以找出到底是什么问题?
I am sure there may be problem due to either:
or this:
Have you defined "spinnerss" actually?
Please check these both the lines, and you should put the Logcat output so that we may catch what exactly the problem?