动态XML,更改文本 [英] dynamic xml, changing text

查看:100
本文介绍了动态XML,更改文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我想这样做:我从服务器获取数据,我需要的时候,例如拉出数0的TextView到BER红色,在任何其他情况下是绿色。我不知道是否有在xml文件放置像if语句或其他地方的方式。

Hello I want to do this: I am pulling data from a server and I need when for example pull out the number 0 the textview to ber red color, on any other case to be green color. I do not know if there is a way of placing something like an if statement in the xml file or somewhere else.

推荐答案

您需要先实例如

TextView tv = (TextView)findViewById(R.id.idOfTextViewInXML);

现在,您可以执行改变这个文本视图请你。例如:

Now you can perform change this text view as you please . For example

if(var==0)
    tv.setText("VALUE IS ZERO");
else
    tv.setBackgroundResource(R.drawable.icon);

这是你需要动态改变视图的功能的方式。你不能真正改变XML本身动态。

This is the way you need to change the features of views dynamically . You can't really change the XML itself dynamically .

所有这必须在Java类来进行。

All this must be performed in the Java class .

这篇关于动态XML,更改文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆