ListView没有显示当ArrayList有2个或更多数据时

时间:2018-06-09 11:32:11

标签: java android listview arraylist android-arrayadapter

    for (int qt = 1; qt == QRLOG; qt++)
    {
        String qrNew = libraryData.getString("CRsaves" + qt, "~~~");
        String qrNewT = libraryData.getString("CRsaves" + qt + "T", "00:00:00");
        String qrNewD = libraryData.getString("CRsaves" + qt + "D", "0000/00/00");
        String qrNewTD = qrNewT + "---" + qrNewD;
        qrLists.add(qrNew);
        qrTimes.add(qrNewTD);
    }

    for (int bt = 1; bt == BRlOG; bt++)
    {
        String brNew = libraryData.getString("BRsaves" + bt, "~~~");
        String brNewT = libraryData.getString("BRsaves" + bt + "T", "00:00:00");
        String brNewD = libraryData.getString("BRsaves" + bt + "D", "0000/00/00");
        String brNewTD = brNewT + "---" + brNewD;
        barLists.add(brNew);
        barTimes.add(brNewTD);
    }
  

QRLOG是CR保存的计数数据,BRLOG是BR保存的计数
   “libraryData”是一个SharedPreferences

            if (position == 1)
            {
                bqrTime.setAdapter(new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1, qrTimes));
                bqrList.setAdapter(new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1, qrLists));
                headB = 1;
                bqrList.setEnabled(true);
                bqrList.setVisibility(View.VISIBLE);
                bqrTime.setEnabled(true);
                bqrTime.setVisibility(View.VISIBLE);
                showPicture.setEnabled(false);
                deleteSave.setEnabled(false);
            }
            if (position == 2)
            {
                bqrTime.setAdapter(new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1, barTimes));
                bqrList.setAdapter(new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1, barLists));
                headB = 2;
                bqrList.setEnabled(true);
                bqrList.setVisibility(View.VISIBLE);
                bqrTime.setEnabled(true);
                bqrTime.setVisibility(View.VISIBLE);
                showPicture.setEnabled(false);
                deleteSave.setEnabled(false);
            }
  

有数据列表...

        <ListView
            android:id="@+id/bqrList"
            android:layout_width="146dp"
            android:layout_height="200dp"
            android:fadeScrollbars="true"
            android:fastScrollEnabled="true" />

        <ListView
            android:id="@+id/bqrTime"
            android:layout_width="238dp"
            android:layout_height="200dp"
            android:fastScrollEnabled="true"
            android:fadeScrollbars="true" />
  

有xml文件

如果数据计数为1,则ListView显示数据而不会出现任何错误。 但是ListView没有显示数据的计数是2或更多..:// 我会疯狂地帮助我..

2 个答案:

答案 0 :(得分:0)

在循环中,您应该!= ==

for (int qt = 0; qt != QRLOG; qt++) {
   // Use qt+1 instead of qt because I initilized it with 0
  }
for (int bt = 0; bt != BRlOG; bt++) {
    //Same for here
  }

在您的代码中

如果您放置QRLOG = 1BRLOG = 1,则循环会运行并显示内容,因为qtbt是使用1启动的。但不是任何其他值。

相当蹩脚的问题。

请在发布前仔细检查您的代码。

答案 1 :(得分:0)

将此代码替换为for for循环

/etc/nginx/sites-available/subdomain.example.com