圆形循环不能在arraylist中使用hashmap显示图像?

时间:2014-09-02 11:11:26

标签: android arraylist hashmap

这就是我想要的:

正如您在图像中看到的,我在每个主要列表位置都存储了子列表。现在我想在主循环工作时从子列表中显示一个项目。如果循环计数器大于子列表大小,则它再次从0开始并逐个递增。

我做了什么:

我从数据库获取数据并将存储的子列表存储在ArrayList

public static ArrayList<ArrayList<HashMap<String, String>>> selectdataloop(SQLiteDatabase db, String TableName,String userfield,String userid,String dbfield, String fieldValue,String selectedplaylistid)
      {

             int count=0;
             ArrayList<ArrayList<HashMap<String, String>>> data = new ArrayList<ArrayList<HashMap<String,String>>>();
             ArrayList<HashMap<String, String>> odata = new ArrayList<HashMap<String,String>>();

            String Query="SELECT * FROM myfiles WHERE (( Datetime('2014-09-01 09:50:15') >= startdate AND Datetime('2014-09-01 09:50:15') <= enddate ) AND (('09:50:15' >= strftime('%H:%M:%S',timer_from) AND '09:50:15' <= strftime('%H:%M:%S',timer_to )) OR ( strftime('%H:%M:%S',timer_from) = '00:00:00' OR '00:00:00' = strftime('%H:%M:%S',timer_to )))) AND ( Monday = 1 OR Everyday = 1) AND download = 1 AND playlist_id = 24 AND user_id='83' ORDER BY position_id ASC, subposition_id ASC";

            Cursor cursor = db.rawQuery(Query, null);
            if(cursor.getCount()<=0)
            {
                cursor.close();
                return data;

            }          
            else
            {   
                 if (cursor.moveToFirst()) 
                 {
                     do 
                     {
                         HashMap<String, String> map = new HashMap<String, String>();
                         String currenttype=cursor.getString(9);

                         String nexttype = null;
                         if(count<cursor.getCount())
                         {   

                             if(cursor.getPosition()==cursor.getCount()-1)
                             {   

                                 nexttype="image";

                                 Log.d("nexttype==image","--->"+cursor.getCount());
                             }  
                             else
                             {
                                 cursor.moveToNext(); 
                                 nexttype=cursor.getString(9);
                                 cursor.moveToPrevious(); 
                             }

                         }

                         count++;

                         map.put(DB_Constant.MYFILES.FILE_ID, cursor.getString(cursor.getColumnIndex(DB_Constant.MYFILES.FILE_ID)));
                         map.put(DB_Constant.MYFILES.FILE_TYPE, cursor.getString(cursor.getColumnIndex(DB_Constant.MYFILES.FILE_TYPE)));
                         map.put(DB_Constant.MYFILES.FILE_SUBTYPE, cursor.getString(cursor.getColumnIndex(DB_Constant.MYFILES.FILE_SUBTYPE)));
                         map.put(DB_Constant.MYFILES.FILE_PATH, cursor.getString(cursor.getColumnIndex(DB_Constant.MYFILES.FILE_PATH)));
                         map.put(DB_Constant.MYFILES.USERID, cursor.getString(cursor.getColumnIndex(DB_Constant.MYFILES.USERID)));
                         map.put(DB_Constant.MYFILES.FILE_SECOND, cursor.getString(cursor.getColumnIndex(DB_Constant.MYFILES.FILE_SECOND)));
                         map.put(DB_Constant.MYFILES.FILE_DOWNLOAD, cursor.getString(cursor.getColumnIndex(DB_Constant.MYFILES.FILE_DOWNLOAD)));
                         map.put(DB_Constant.MYFILES.FILE_STARTTIME, cursor.getString(cursor.getColumnIndex(DB_Constant.MYFILES.FILE_STARTTIME)));
                         map.put(DB_Constant.MYFILES.FILE_ENDTIME, cursor.getString(cursor.getColumnIndex(DB_Constant.MYFILES.FILE_ENDTIME)));
                         map.put(DB_Constant.MYFILES.FILE_TIMERFROM, cursor.getString(cursor.getColumnIndex(DB_Constant.MYFILES.FILE_TIMERFROM)));
                         map.put(DB_Constant.MYFILES.FILE_TIMERTO, cursor.getString(cursor.getColumnIndex(DB_Constant.MYFILES.FILE_TIMERTO)));
                         map.put(DB_Constant.MYFILES.FILE_STUDIOFORMAT, cursor.getString(cursor.getColumnIndex(DB_Constant.MYFILES.FILE_STUDIOFORMAT)));
                         odata.add(map);

                         if(currenttype.equalsIgnoreCase("image") || currenttype.equalsIgnoreCase("video"))
                         {
                             data.add(odata);
                             odata = new ArrayList<HashMap<String,String>>();


                         }
                         else if(nexttype.equalsIgnoreCase("image") || nexttype.equalsIgnoreCase("video"))
                         {
                             data.add(odata);
                             odata = new ArrayList<HashMap<String,String>>();

                         }

                         // get  the  data into array,or class variable

                     } while (cursor.moveToNext());

                 }

             }   
            Log.e("data","---->"+data.size());
            Log.e("data","---->"+data);
            cursor.close();
            return data;
      }

ArrayList<ArrayList<HashMap<String, String>>> data2 = new ArrayList<ArrayList<HashMap<String,String>>>();
            data2=DB_Helper.selectdataloop(mSQLiteDatabase, "", "", "", "", "", "");
            for(int i=0;i<data2.size();i++)
            {
                Log.v("Main Loop","----i----"+i);

                ArrayList<HashMap<String,String>> idata=data2.get(i);
                if(i<idata.size())
                {   
                    String id=idata.get(i).get("file_id").toString();
                    Log.e("i<data.size","----------"+id);
                }
                else
                {
                    String id=idata.get(0).get("file_id").toString();
                    Log.d("i>data.size","----------"+id);

                }

            }

enter image description here

0 个答案:

没有答案