0

Good day, After having overriden isEnabled() in my custom adapter class, i want to be able to change the color of my Textview for some items where isEnabled() returned false. To do this i have to check for each item position in the getView() Method. My Question is how can i get this Textview based on the position in the list

i tried to find a way to use mstring[position] in the getView, but this will just return a string. and not the views.

Any ideas? Much Appreciated as Always

code:

    @Override
    public int getCount(){
        return mstring.length;    //Array of Strings
    }

    @Override
    public String getItem(int position){
        return mstring[position];
    }

    @Override
    public long getItemId(int position){
        return position;
    }

@Override
        public boolean isEnabled(int position) {
            int set = 0;
            switch(position){
            case DATA_A:
                    if(a_data == 1){
                        set = 1;
                    }else {
                        set = 0;
                    }
            break;

            case DATA_B:
                if(b_data == 1){
                    set = 1;
                }else {
                    set = 0;
                }
            break;

            case DATA_C:
                if(c_data == 1){
                    set = 1;
                }else {
                    set = 0;
                }
            break;
            }

            return (set == 1)? true:false;
        }

        @Override
        public View getView (int position, View convertView, ViewGroup parent){
            ViewHolder holder;

            if(convertView == null){
                LayoutInflater inflater = LayoutInflater.from(mContext);
                convertView = inflater.inflate(ViewResourceId, null);
                holder = new ViewHolder();


              holder.imageview = (ImageView)convertView.findViewById(R.id.menu_image_item);
              holder.text_title = (TextView)convertView.findViewById(R.id.menu_textview_id);
              holder.arrowImageView = (ImageView)convertView.findViewById(R.id.menu_arrow_id);

              convertView.setTag(holder);

            }
            else{
                holder = (ViewHolder)convertView.getTag();
            }

            //set Array text values defined in xml to textview
            String title = mstring[position];
            holder.text_title.setText(title);

            //set Array icons values defined in xml to textview
            holder.imageview.setImageDrawable(icons.getDrawable(position));


         /*!!!Having the troubles here!!!!! giving NullPointerException!!!! and not
          sure what to try*/

         if(!myListView.getChildAt(position).isEnabled()){

               holder.text_title.setTextColor(R.color.greyed_text_color);
           }

            return convertView;
        }


    }
4

1 回答 1

1

您应该发布整个代码,否则很难发现问题所在。如果我是你,我会检查返回此行的结果:

myListView.getChildAt(position)

您在此行中使用的:

if(!myListView.getChildAt(position).isEnabled()){
于 2013-07-03T13:58:24.853 回答