Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 找不到AdapterView[微调器]_Java_Android_Android Adapterview - Fatal编程技术网

Java 找不到AdapterView[微调器]

Java 找不到AdapterView[微调器],java,android,android-adapterview,Java,Android,Android Adapterview,我目前正在使用我的第一个旋转器。但是我有点在onItemSelectedListener期间被卡住了,因为我无法实现它。我第一次尝试遵循《公共物品》一书中的方法,但它会起作用——但我的方法现在也不起作用 起初,我试图让我的活动直接实现AdapterView——但唯一的结果是eclipse告诉我AdapterView接口不可用,并要求我创建它。。。但是我现在又犯了同样的错误 public class Lunchplace extends Activity { /** Called when the

我目前正在使用我的第一个旋转器。但是我有点在onItemSelectedListener期间被卡住了,因为我无法实现它。我第一次尝试遵循《公共物品》一书中的方法,但它会起作用——但我的方法现在也不起作用

起初,我试图让我的活动直接实现AdapterView——但唯一的结果是eclipse告诉我AdapterView接口不可用,并要求我创建它。。。但是我现在又犯了同样的错误

public class Lunchplace extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mensa);
    Context c = getApplicationContext();

    Spinner dateSelection = (Spinner)findViewById(R.id.date);

    //ArrayAdapter<String> aa = new ArrayAdapter<String>(this, android.R.)
    // get all the little tidbits of extra informations
    Bundle extras = getIntent().getExtras();

    String location = extras.getString("Mensa");
    // this function will download the Lunchfile - if necessary
    Data lunchData = new XMLData(c);

    // set the header text
    TextView mensaname = (TextView)findViewById(R.id.header);
    mensaname.setText(location);

    // get the spin view out of the xml
    Spinner spin = (Spinner)findViewById(R.id.date);

    // attach it to an adapter
    ArrayAdapter adapter = ArrayAdapter.createFromResource(
            this, R.array.days, android.R.layout.simple_spinner_item);
    // I should be able to put a custom layout of the spinner in there.. I bet
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spin.setAdapter(adapter);


    spin.setOnClickListener(
             new  AdapterView.OnItemSelectedListener() {           

           @Override
           public void onItemSelected(AdapterView<?> parent, 
             View view, int position, long id) {
           }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub

        }
             }
    );

    // set the current day of the week as the default selection
    spin.setSelection(Tools.getDayOfWeek());

    // get the tablelayout
    TableLayout tl = (TableLayout)findViewById(R.id.MenuTable);
    lunchData.getMenuforDay(c,tl,location);

    TextView counterTV = new TextView(c, null, R.style.MenuField);

    }
}
公共课堂午餐场所扩展活动{
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.mensa);
Context c=getApplicationContext();
微调器日期选择=(微调器)findViewById(R.id.date);
//ArrayAdapter aa=新的ArrayAdapter(这个,android.R.)
//获取所有额外信息的小道消息
Bundle extras=getIntent().getExtras();
字符串位置=extras.getString(“Mensa”);
//如有必要,此功能将下载文件
数据=新的XMLData(c);
//设置标题文本
TextView mensaname=(TextView)findViewById(R.id.header);
mensaname.setText(位置);
//从xml中获取自旋视图
微调器旋转=(微调器)findViewById(R.id.date);
//将其连接到适配器上
ArrayAdapter=ArrayAdapter.createFromResource(
这个,R.array.days,android.R.layout.simple\u spinner\u item);
//我应该可以在那里放置一个微调器的自定义布局..我打赌
setDropDownViewResource(android.R.layout.simple\u微调器\u下拉菜单\u项);
spin.setAdapter(适配器);
spin.setOnClickListener(
新建AdapterView.OnItemSelectedListener(){
@凌驾
已选择公共无效项(AdapterView父项,
视图、整型位置、长id){
}
@凌驾
未选择公共无效(AdapterView arg0){
//TODO自动生成的方法存根
}
}
);
//将一周中的当前日期设置为默认选择
spin.setSelection(Tools.getDayOfWeek());
//获取表格布局
TableLayout tl=(TableLayout)findViewById(R.id.MenuTable);
午餐数据。getMenuforDay(c、tl、位置);
TextView counterTV=新的TextView(c,null,R.style.MenuField);
}
}

有人知道我如何解决这个问题吗?

实现OnItemSelectedListener没有什么特别之处。试着这样做:

spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if ("YourDayToHandle".equals(spinner.getSelectedItem())) {
                // do smth useful here
            }
        }

    public void onNothingSelected(AdapterView<?> parent) {}
});
spinner.setOnItemSelectedListener(新的OnItemSelectedListener(){
已选择公共视图(AdapterView父视图、视图视图、整型位置、长id){
if(“YourDayToHandle”.equals(spinner.getSelectedItem())){
//smth在这里有用吗
}
}
未选择的公共无效(AdapterView父项){}
});