在 Android 中将数据加载到 TextView [英] Loading data to TextView in Android

查看:66
本文介绍了在 Android 中将数据加载到 TextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 XML 标记,如Yes,No,Dontknow",我正在解析 XML 文件并获取数据.现在我需要在单独的 TextView 中显示每个选项,即:'yes' 应该显示在一个 TextView 中,'No' 应该显示在另一个 TextView 中,'Dontknow' 应该显示在另一个 TextView 中,但是我该怎么做,谁能给我一些想法(我是 Android 新手).

I have a XML tag like "Yes,No,Dontknow " and I am parsing the XML file and getting the data. Now I need to display each option in separate TextView, i.e: 'yes' should be displayed in one TextView, 'No' should be displayed in another TextView, and 'Dontknow' should be displayed in another TextView, but how can I do this, can anyone give me some idea (I am new to Android).

推荐答案

您可以使用字符串标记器:

You can use string tokenizer:

StringTokenizer tokens = new StringTokenizer(theString, ",");
while( tokens.hasMoreTokens() ){
    String token = tokens.nextToken();
    // here you must have the reference to the text view...
    textView.setText(token);
}

如果您以编程方式创建文本视图,则必须在循环内创建或引用这些文本视图.否则,如果文本视图是静态的,您最好将每个标记放在一个数组或其他东西中(words[0] 将是 Yes,word[1] 将是 No 等),然后手动设置这些字符串.

If you are creating the text views programmatically, then you must create or reference those text views inside the loop. Other wise, if the text views are static, you better put each token inside an array or something (words[0] will be Yes, word[1] will be No, etc) and then you set those strings manually.

这篇关于在 Android 中将数据加载到 TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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