嗨,我对 android 编程完全陌生,并通过平板电脑使用 AIDE。
我正在尝试使用 Spinner 框创建一个非常基本的程序,该程序可以输出我通过 TextView 或 System.Out.printIn 所做的选择。(也许是 Hello world 的下一步——如果你愿意的话)
由于某种我无法理解的原因,当我已经在导入中检查了这一点时,编译器拒绝识别 OnClickListener 并给出错误消息“Android.Widget.Spinner 中的未知方法 OnClickListener”。
As a matter of interest I have changed the name of the Spinner and the error seems to dissapear, the problem then is the Spinner name. I have tried several variations on this, and have came to the conclusion that the best option for me is to create a variable just after Main Acivity, and before the layout is declared.
我还禁用了其中一项覆盖以解决我的问题
有没有人知道问题可能是什么?
package com.BGilbert.AUC;
import android.app.*;
import android.os.*;
import android.widget.*;
import android.view.View.OnClickListener;
import android.widget.Spinner.*;
import android.view.*;
public class MainActivity extends Activity {;
String Fbstring;
OnClickListener Myonclick;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.main);
final Spinner Fbspinner=(Spinner)findViewById(R.id.Spinner);
// The problem is with this line. OnClickListener just wont be
// recognised
Fbspinner.OnClickListener(Myonclick);
}
// Override previously disabled
@Override
public void Onselect(AdapterView<?> parent,View V, int pos, long id) {
Fbstring = parent.getItemAtPosition(pos).toString();
System.out.println(Fbstring);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
}