没有为我的微调器调用OnItemSelectedListener()

时间:2011-02-06 19:06:43

标签: android selection spinner

嗨我有一个使用visibility = gone atribute隐藏的微调器。我使用spinner.performclick()调用微调器列表,这个工作正常,除了在微调器列表中选择一个项目时,我的onselect监听器永远不会被调用。请帮忙:)

唯一引发的catlog警告是“窗口已经集中,忽略焦点增益”

        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
        }
        });

1 个答案:

答案 0 :(得分:9)

保留微调器的可见性为INVISIBLE,但设置android:layout_width =“0dp”和android:layout_height =“0dp”

这样,在你调用performClick()之前,微调器实际上不在UI中,然后它出现,用户做出选择并且微调器折叠回0x0 ......然后你得到了onItemSelected事件。