0

我正在使用AutoCompleteTextView并很好地获得建议,我想禁用TextView我能够做到的位置 1 的礼物。

主要问题是我想将TextView位置 1 的当前颜色设置为黑色。
我已经设置了它的颜色,但是当我滚动建议列表时,所有 TextView 颜色都会变为黑色。

下面是我的代码,其中我禁用了位置 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;
    }
4

2 回答 2

0

我的 ListView 有问题,我相信它与您的类似。

我的问题是当我到达 ListView 的底部时,“位置”的值(在 getView 内)一直恢复为零;因此,当我向上滚动 ListView 时,我从底部的零开始。

我通过强制我的“视图”为空来解决这个问题,在你的情况下是 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;
    }

或者,如果您知道第一个 TextView 的值,您可以这样做:

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

    if(viewTitleText=="owen") {
       mView.setBackgroundColor(Color.BLACK);
    } else {
       mView.setBackgroundColor(Color.GREEN);
    }
于 2013-10-03T14:17:40.470 回答
0

在这里查看我的答案

在这里我重复我的回答。

使用以下代码更改下拉菜单的背景颜色,例如

 autocomplete.setDropDownBackgroundResource(R.color.autocompletet_background_color);  

您可以在 string.xml 中设置这样的值

 <color name="autocompletet_background_color">#EFEFEF</color>    

如果要更改下拉项的文本颜色,请执行以下操作。

在适配器类中。

 @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("check some condition if you want. "))
    {
        text.setTextColor(Color.parseColor("#999999"));
        text.setText("set some text");               
    }           
    else
    {
        text.setTextColor(Color.parseColor("#cc3333"));
            text.setText(getItem(position));
    }           
}
return mView;

如果您有任何问题,请告诉
我。:-)

于 2013-12-26T14:14:26.050 回答