0

I am using AutoCompleteTextView and getting the suggestions well, I want to disable the TextView present at position 1 which I am able to do.

The main issue is I want to set color of TextView present at position 1 to black.
I have set its color but when I scroll the suggestion list all TextView color get changes to black.

below is my code where I have disabled the textview present at position 1.

@Override
    public boolean isEnabled(int position) {
        // TODO Auto-generated method stub
        if(getItem(position).contains("Or, did you mean"))
            return false;
        else
        return super.isEnabled(position);
    } 

@Override
    public View getView(int position, View v, ViewGroup parent)
    {
        View mView = v ;
        if(mView == null){
            LayoutInflater vi = (LayoutInflater)appContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            mView = vi.inflate(id, null);
        }

        TextView text = (TextView) mView.findViewById(R.id.textview);


        if(getItem(position) != null )
        {
            text.setTypeface(faceBold);
            if(getItem(position).equals("Or, did you mean..."))
            {
                text.setTextColor(R.color.black);
                text.setText("Or, did you mean");

            }
            else
            {
                text.setText(getItem(position));
            }                
        }

        return mView;
    }
Pratik
  • 1,531
  • 3
  • 25
  • 57

1 Answers1

0

I had a problem with my ListView, which I believe is similar to yours.

My problem was that the value of 'position' (within getView) kept reverting back to zero when I reached the bottom of the ListView; so when I scrolled back up the ListView I was starting from zero at the bottom.

I got around the problem by forcing my 'View' to null, in your case mView.

public View getView(int position, View convertView, ViewGroup parent) {

        mView = null;   

        if (convertView == null) {
            LayoutInflater vi = (LayoutInflater)appContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            mView = vi.inflate(id, null);
        }
        return mView;
    }

Or possibly if you know the value that the first TextView will be you could do:

    final String viewTitleText = ((TextView)mView.findViewById(R.id.textview)).getText().toString();

    if(viewTitleText=="owen") {
       mView.setBackgroundColor(Color.BLACK);
    } else {
       mView.setBackgroundColor(Color.GREEN);
    }
Owen Hall
  • 1
  • 2