Android 如何在文本视图或任何内容中打印数组 [英] Android how to print a array in text view or anything

查看:45
本文介绍了Android 如何在文本视图或任何内容中打印数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个单词数组,我想在单击按钮后以文本视图将单词数组打印到屏幕上.我正在使用 for 循环遍历整个列表,然后设置文本,但是我不断收到错误消息,而且它只会替换最后一个值,因此它不会打印整个数组.如果有人可以向我解释如何像 g.drawSting() 但 android 版本那样做,那就太好了.我的代码 rt 现在不在我身边,但它类似于:- 顺便说一句,我是 android 的初学者,大概可以通过这个问题来判断.

I have a array of words and I would like to print the array of words onto the screen in a text view after a button is clicked. i was using a for loop to go through the whole list and then set text, but i keep getting a error with that plus it will just replace the last value, so it wont print the whole array. If anybody could explain to me how to do like a g.drawSting() but android version that would be great. my code rt now is not with me but it something like: -I'm a beginner to android btw, probably could tell by this question tho.

public void onCreate(Bundle savedInstanceState)
{
//code for a button just being pressed{
 //goes to two methods to fix the private array{
     for(int y=0; y<=array.size()-1; y++){
        textArea.setText(aarray.get(y));   //prints all strings in the array
 }
}
}

推荐答案

int arraySize = myArray.size();
for(int i = 0; i < arraySize; i++) {
myTextView.append(myArray[i]);
}

如果要一张一张打印,就用

if you want to print one by one, then use

myTextView.append(myArray[i]);
myTextView.append("
");

附注:谁建议把.size()改成.length(),谢谢你的建议.

PS: Whoever suggesting to change .size() to .length(), thanks for you suggestion.

仅供参考,提问者提到的变量名是array.size(),所以答案也有相同的变量名,以方便提问者.

FYI, The questioner mentioned the variable name is array.size() in question, so the answer also having the same variable name, to make it easier for the questioner.

如果您的变量 (myArray) 是 Array 使用 myArray.length(),如果它是 ArrayList 使用 myArray.大小()

if your variable (myArray) is an Array use myArray.length(), if it is ArrayList use myArray.size()

这篇关于Android 如何在文本视图或任何内容中打印数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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