开发者

Listview...how to conditionally replace a value with a string

my ANDROID app presents a listview, from a database cursor and XML, that needs to replace the values in a column with various words based on the integer value contained in the cursor. For example, if the value is -1, replace it with the word "Invalid", but if the value is >= 0 then just display the value.

开发者_JAVA技巧

I was under the impression this could magically be done via XML... TIA.


you can either use JS regular expressions (regexp) to replace them or use PHP Class


Since you don't state what language you are using, there might be some difference to the language of your choice:

yourValue = ( '-1' == yourValue ) ? 'Invalid' : yourValue;

This will replace the contents of yourValue with 'Invalid' if it is -1 or let it stay the same.

You need to modify this depending on how you access your variables (i.e. dollar signed prefixed: $yourValue).

If your language is type-aware, you might want to make sure that yourValue is already a string.

This is what you should do when printing the output or while reading the content of your file. XML itself does not change the values for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜