round looping not work in arraylist with hashmap for display images?

匆匆过客 提交于 2019-12-24 12:23:08

问题


This is what I want:

As you can see in the image I have stored sub-Lists on each main List position. Now I want to display one item from sub-list when main loop is working. If looping counter is greater than sub-List size then it starts again from 0 and increments one by one.

What I have done:

I have got the data from database and stored sub-Lists in a 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);

                }

            }

来源:https://stackoverflow.com/questions/25622025/round-looping-not-work-in-arraylist-with-hashmap-for-display-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!