Android列表下拉滚动条移动更改列表下拉列表中的内容样式

问题描述

这是我的下面的代码

public class EntityAdapter extends ArrayAdapter<EntityDropDown> {

    public EntityAdapter(Context context,ArrayList<EntityDropDown> locations) {
        super(context,locations);
    }

    public View getView(int position,@Nullable View convertView,@NonNull ViewGroup parent) 
    {
        return initView(position,convertView,parent);
    }


    public View getDropDownView(int position,@NonNull ViewGroup 
parent) {
        return initView(position,parent);
    }

    @Override
    public boolean isEnabled(int position){

        EntityDropDown entity = getItem(position);

        if (entity.getEntityName().length() == 1) {
            return false;
        }
        else {
            return true;
        }
    }    


   private View initView(int position,View convertView,ViewGroup parent) {

    
       if (convertView == null) {
           convertView = LayoutInflater.from(getContext()).inflate(
                   R.layout.drop_down_rows,parent,false
           );
       }   

       TextView textView = convertView.findViewById(R.id.row_text_view_1);

       EntityDropDown entity = getItem(position);

       if (entity != null) {

           if (entity.getEntityName().length() == 1) {
               textView.setText(entity.getEntityName());
               textView.setTypeface(Typeface.DEFAULT_BOLD);
               textView.setTextSize(TypedValue.COMPLEX_UNIT_SP,20);

           } else {
               textView.setText(entity.getEntityName());
           }
       }   

       return convertView;
    }
}

我的实体列表为

("a","AA","abcd","b","bbb","bcde",....
  "z","zzz","zabc")

我执行

var adapter = EntityAdapter()

adapter = EntityAdapter(
        requireContext(),entityList
    )

listView.adapter = adapter

其中EntityList为上面的

我要突出显示粗体的字母,它们的长度为1,而不是长度为1,它们是正常/常规的。

问题是当我上下滚动时,列表下拉列表的内容随机更改,大于1的长度是粗体,我尝试调试但没有找到解决方法

我们将不胜感激,谢谢您。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...