OnItemSelectedListener() not being called for my spinner

倖福魔咒の 提交于 2019-12-02 02:15:42

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/4915432/onitemselectedlistener-not-being-called-for-my-spinner

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!