OnItemSelectedListener()不会被调用我的微调 [英] OnItemSelectedListener() not being called for my spinner

查看:165
本文介绍了OnItemSelectedListener()不会被调用我的微调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我使用的知名度都隐藏着一个微调=不见了属性附加伤害。我所说的微调列表使用spinner.performclick(),这在我的ONSELECT监听器永远不会被调用的微调列表中选择一个项目时,工作正常,除了这一点。请帮助:)

被抛出的唯一警告目录下载是窗口已经集中,忽略聚焦增益

  catagorySpinner.setOnItemSelectedListener(新OnItemSelectedListener(){
        @覆盖
        公共无效onItemSelected(适配器视图<> parentView,查看selectedItemView,INT位置,长的id){
            CashDB CDB =新CashDB(getBaseContext());
            cdb.open();
            光标C = cdb.FetchCatagory(ID);
            startManagingCursor(C);
            c.moveToFirst();
            串newCatagoryName = c.getString(c.getColumnIndexOrThrow(CashDB.CATAGORY_NAME));
            c.close();
            areYouSureDialog(你确定?,你确定要删除catagory+
                    + catagoryName +'+,并将所有交易+'的
                    + newCatagoryName ++?,
                    catagoryIcon,catagoryName,newCatagoryName,DELETE_CATAGORY_MOVE,catagoryId);
        }

        @覆盖
        公共无效onNothingSelected(适配器视图<>为arg0){
            // TODO自动生成方法存根
        }
        });
 

解决方案

离开的可见性微调,在看不见的,但设置了android:layout_width =0dp和a​​ndroid:layout_height =0dp

这样,微调实际上不是在用户界面,直到调用performClick(),那么它的出现,使得用户在选择和微调折叠回为0x0 ......,你会得到onItemSelected事件。

Hi i have a spinner that i have hidden using visibility = gone atribute. i call the spinner list using spinner.performclick() , this works fine except for that when selecting an item in the spinner list my onselect listener is never being called. please help:)

the only catlog warning being thrown is "window already focused, ignoring focus gain"

        catagorySpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
            CashDB cdb = new CashDB(getBaseContext()); 
            cdb.open();
            Cursor c = cdb.FetchCatagory(id);
            startManagingCursor(c);
            c.moveToFirst();
            String newCatagoryName = c.getString(c.getColumnIndexOrThrow(CashDB.CATAGORY_NAME));
            c.close();
            areYouSureDialog("Are You Sure?", "Are you sure you want to delete the catagory " +'"' 
                    + catagoryName + '"'+ " and move all of the transactions to " +'"' 
                    + newCatagoryName + '"' + " ?",
                    catagoryIcon, catagoryName,newCatagoryName, DELETE_CATAGORY_MOVE, catagoryId);
        }

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

解决方案

Leave the visibility for the spinner at INVISIBLE, but set the android:layout_width="0dp" and android:layout_height="0dp"

That way, the spinner is effectively not in the UI until you call performClick(), then it appears, user makes the choice and the spinner collapses back to 0x0 ... and you get the onItemSelected event.

这篇关于OnItemSelectedListener()不会被调用我的微调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆