简体   繁体   English

Android:在Java中更改“选定列表项”的TEXT颜色

[英]Android:change the the TEXT color of Selected list Item in Java

I am working on a dynamic Android application in Java where a list view gets values from database. 我正在使用Java在动态Android应用程序中进行工作,其中列表视图从数据库中获取值。

What I am looking for is how to change the TEXT color of Selected list Item in that list, and the color of that text should remain changed to indicate that this item has been selected, no matter if the activity has been changed. 我要寻找的是如何更改该列表中“选定列表”项的TEXT颜色,并且该文本的颜色应保持更改,以指示该条目已被选中,无论活动是否已更改。 Whenever we come back to that activity to make another selection, that color changing item should be there still with the changed Text color. 每当我们回到该活动进行另一选择时,该更改颜色的项目应仍保留在其中,并且更改后的文本颜色也是如此。

When you select an item, you will need to save that information in a static data structure. 选择一个项目时,您需要将该信息保存在静态数据结构中。 If you want the selection to be persistent (even if the app is closed), then you will need to store the selection indicator in your database. 如果您希望选择是持久的(即使应用程序已关闭),则需要将选择指示符存储在数据库中。 When you read your database to extra the data, use the "selection indicator" in your adapter to decide what color to use. 当您读取数据库以增加数据量时,请使用适配器中的“选择指示器”来确定要使用的颜色。

Simply changing the textColor of your textField will not persist when you return to that activity. 当您返回该活动时,仅更改textField的textColor不会持久。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM