Question

I'm doing my own Adapter to use in a GridView and represent a calendar. My problem is when I use setClickable() and setFocusable() set to false I can click on the layout... but if I set it to true I can´t... Thanks for the attention. I pasted my code.

 public View getView(final int position, View convertView, ViewGroup parent) {  
            // TODO Auto-generated method stub  

            String item = items[position];

             vi=convertView;
             final TextView tv;

            if(convertView==null){
                LayoutInflater inflater = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                vi = inflater.inflate(R.layout.dato, null);}

           tv = (TextView) vi.findViewById(R.id.textViewDia);

            if(item.equals("")){

                tv.setText(""+item);
                tv.setClickable(false);
                tv.setFocusable(false);
                tv.setEnabled(false);

            }
            else{
                 tv.setText(""+item);
            }



            return vi;  
        }

EDIT: I add this to my code like says in first answer but still working wrong:

 @Override
        public boolean isEnabled(int position){

            return true;
        }

        @Override
        public boolean areAllItemsEnabled(){

            return false;
        }

SOLUTION: I found the solution, is like says @FunkTheMonk but I understood wrong my bad english sorry =)

 @Override
        public boolean isEnabled(int position){
            if(items[position].equals(""))
            return false;

            else
                return true;
        }

        @Override
        public boolean areAllItemsEnabled(){

            return true;
        }
Was it helpful?

Solution

By making the layout clickable, it is consuming the click event. When the layout isn't clickable, the click event is instead consumed by the GridView, and will be processed by any OnItemClickListener set on that GridView.

Override areAllItemsEnabled to return false, override isEnabled and do the check there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top