有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何为我的结构获得无限数量的项

  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个物品(位置)才能这样做。 我怎样才能无限次地编写这些代码呢


共 (1) 个答案

  1. # 1 楼答案

    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);
    

    这是一个简单的解决方案,将为您带来一个窍门