java - 我怎样才能为我的结构获得无限数量的项目

标签 java android list android-listview

  Article article = null;
  Article article2 = null;
  Article article3 = null;
  if (position == 0)
  {
  article = getItem(0);
  article2 = getItem(1);
  article3 = getItem(2);
  }
  else if (position == 1)
  {
  article = getItem(3);
  article2 = getItem(4);
  article3 = getItem(5);
  }
  else if (position == 2)
  {
      article = getItem(6);
      article2 = getItem(7);
      article3 = getItem(8);
  }

我需要像这样获取我的项目列表,但直到第 90 个项目(位置)我才能做到这一点。 我怎样才能无限次地编写这些代码。

最佳答案

I need to get my item list like this, but i can't do that until 90th item(position). How can i write these codes for infinite times.

你可以这样做:

article = getItem((position * 3));
article2 = getItem((position * 3) + 1);
article3 = getItem((position * 3) + 2);

这是一个简单的解决方案,并且会给你带来好处。

关于java - 我怎样才能为我的结构获得无限数量的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22991725/

相关文章:

java - 无法将符号解析为JSONObject

android - 如何在 android 中按需更改通话语音? (将男人换成女人等)

java - 无法取消 Android 闹钟管理器的闹钟

android - 能够连接到服务器的设备白名单

python - 根据某些字符将列表拆分为更小的列表

java - 从位置类获取 "getDistance"并使用 if 条件在目标类中使用它

Java:避免写入和读取文件

python - 替换列表中的特定元素

Java - 从包含指定的ArrayList中删除字符串

java - Oracle Blobs - 存储大小还是计算?