领域列表视图加载缓慢

时间:2016-05-30 23:16:37

标签: android listview realm

我已经在Android上使用Realm几天了,而且我很喜欢它。但是,最近我注意到使用领域适配器将数据加载到列表视图时出现问题。每当我使用listview启动活动或恢复时,它们都会延迟。延迟是显而易见的。它实际上扰乱了整个ux的互动。我尝试过使用异步方法,但延迟仍然存在。顺便说一下,我只在列表视图中加载了15个项目! 这是我目前的代码。

public static void printAll(int n1, int n2, double[][] m, 
           String[] labs, double scaling, JTextArea outext)
{
  // Some definitions for handling output formating
  NumberFormat myFormat = NumberFormat.getNumberInstance();
  FieldPosition fp = new FieldPosition(NumberFormat.INTEGER_FIELD);
  // Following suppresses e.g. comma in 1,000 = 1000 for English locale.
  myFormat.setGroupingUsed(false);

  int w; 
  double maxval; 
  maxval = SMALL;

  for (int i =0; i < n1; i++) {
      for (int j =0; j < n2; j++) {
          // Scale up values by 'scaling' factor
          if (m[i][j] > maxval) maxval = m[i][j];
      }
  }

  String temp = myFormat.format(maxval*scaling, 
                  new StringBuffer(), fp).toString();
  // Output display field width of each number: extra 2 to 
  // account for possible minus sign, and 1 space.
  w = fp.getEndIndex() - fp.getBeginIndex() + 2;
  // System.out.println(" Output field width = " + w);

  // In the next few lines we say how we want numbers to appear.
  // max integer digits = max no. of digits before dec. point
  // max fraction digits = max no. of digits following dec. point
  // min fraction digits = min no. of digits following dec. point
  myFormat.setMaximumIntegerDigits(w);
  // We will set min and max nos. of digits following dec. point to 0
  myFormat.setMaximumFractionDigits(0);
  myFormat.setMinimumFractionDigits(0);
  for (int i=0; i<n1; i++)
  {
      // First handle cols for labels, QLT, PDS, INR:
      String myString = labs[i];
      myString = getSpaces(4 - myString.length()) + myString; 
          outext.append("|" + myString + "|");
      for (int j = 0; j < 3; j++) {
              String valString = myFormat.format(
                   scaling*m[i][j], new StringBuffer(), fp).toString();
      // With a max field width of w, we pack spaces before val.
              valString = getSpaces(4 - fp.getEndIndex()) + valString;
              outext.append(valString);
      }

      // Print each row, elements separated by spaces
          for (int j = 3; j < n2; j++)
              {
          // Scaling is in thousandths; but note if +ve only.
          w = 4;      // All cntr and corr are positive.
          if (j/3 == (double)j/3.0) {  // Here, will handle proj.
          outext.append("|");
          w = 5;                   // Allow for -ve vals.
          }
                  String valString = myFormat.format(
                      scaling*m[i][j], new StringBuffer(), fp).toString();
          // With max field width of w, we pack spaces before val.
                  valString = getSpaces(w - fp.getEndIndex()) + valString;
                  outext.append(valString);
              }
      outext.append("|");
          // Start a new line at the end of a row
      outext.append("\n");
      }
}

我似乎无法解决问题所在。提前谢谢。

0 个答案:

没有答案