For循环填充数组?

编程入门 行业动态 更新时间:2024-10-24 12:26:16
本文介绍了For循环填充数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在ImageAdapter类本教程中,为http://开发商。 android/resources/tutorials/views/hello-gridview.html

In the ImageAdapter class of this tutorial, developer.android/resources/tutorials/views/hello-gridview.html

我想创建和填充使用for循环的数组。但似乎不管我在哪里把它,它会导致错误。

I would like to create and populate an array using a for loop. But it seems no matter where I place it, it causes an error.

例如,在私人语境mContext; 我把下面的,它导致错误。我认为循环是好的,我只是不知道在那里我可以把它。结果

For example, under private Context mContext; I put in the following and it causes an error. I think the loop is good, I'm just not sure where I can put it.

私有String [] myString的;对于(INT数= 0;&号LT; = 12;数++){    MyString的[数字] =形象+号;}

推荐答案

创建和填充在构造函数中的阵列。不要忘了实际上的实例化数组你开始填充它。

Create and populate the array in the constructor. Don't forget to actually instantiate the array before you start populating it.

public ImageAdapter(Context c) { mContext = c; myString = new String[12]; //create array for (int number = 0; number < myString.length; number++) { myString[number] = "image" + number; } }

您或许应该直接跃入前的Andr​​oid了一​​下你的Java工作。

You should perhaps work on your Java a bit before jumping straight into Android.

更多推荐

For循环填充数组?

本文发布于:2023-08-05 21:21:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1308128.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!