How to change listview item background color using if condition Android

我的未来我决定 提交于 2020-02-16 11:31:07

问题


I'm creating an app with listview and I added few values like 101,102 to 110 to the listview. Now I have to change the listview item background colour using edittext. For example if I type 101 and click submit button, background colour of 101 should change. Please help. Please......


回答1:


First Declare the layout of adapter

linearlayout = itemView.findViewById(R.id.linearLayout);

then set color if match the number in onBindViewHolder()

if((position.Value())==typedValue){
    holder.linearlayout.setBackgroundColor(Color.parseColor("#FF003B"));
}



回答2:


You can try

listView.setSelectorColor(getResources().getColor(R.color.colorPrimaryDark))

You can see this [Change background color of selected item on a ListView



来源:https://stackoverflow.com/questions/59307997/how-to-change-listview-item-background-color-using-if-condition-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!