如何使用领域的增量名操纵? [英] How to manipulate with incremental names of fields?

查看:123
本文介绍了如何使用领域的增量名操纵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何与字段名称增量操纵?
例如:

How to manipulate with incremental names of fields? For example:

 myBitmapField1
 myBitmapField2
 myBitmapField3
 ...

时的方式将它们添加到FieldManager在这样或类似的方式:

Is a way to add them to FieldManager in a way like this or similar:

int i = 0;
while (i < 1000)
 {
 i = i + 1;
 if (myCounter == i)
 myVerticalFieldManager.add(_myBitmapField[i]);
 }
   ...

有一个办法,像这样的文件名的增量名操作:

There is a way to manipulate with incremental names of file names like this:

 myBitmapField.setBitmap(Bitmap.getBitmapResource("a" + myCounter + ".png"));

不过,我需要的字段名称以操纵!我怎么能这样做呢?

But I need to manipulate with names of fields ! How could I do that?

推荐答案

理想的情况下,不 - 使用数组(或可能是列表)代替。如果你的有无的使用名称,创建一个合适的地图(如的HashMap )的名称值。

Ideally, don't - use an array (or possibly a List) instead. If you have to use names, create an appropriate Map (e.g. a HashMap) from names to values.

虽然你的可以的使用反射接入领域 - 至少在正常的Java - 这将是一个糟糕的设计在这里。你有多个相关的值,因此使用集合...它就是这么简单。

While you can access fields using reflection - at least in "normal" Java - it would be a poor design here. You've got multiple related values, so use a collection... it's as simple as that.

这篇关于如何使用领域的增量名操纵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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