// 改变list的颜色 private void changeTextColor() { // 遍历mList获取每个条目的数目 for (int i = 0; i < mList.size(); i++) { int count = 0; for (int j = 0; j < mList.get(i).size(); j++) { if (mList.get(i).get(j) != null) { count++; } } mContentCount[i] = count; adapter.setContentCount(mContentCount); } adapter.notifyDataSetChanged(); int position = 0; // 根据mList里面是否有内容来设置字体的颜色 for (List<Map<String, Object>> mLi : mList) { // System.out.println("map : " + mLi.toString()); int content = 0; for (Map<String, Object> map : mLi) { if (map != null) { if (map.get("path") != null) { System.out.println("file path : " + map.get("path")); content++; } } } if (content != 0) { adapter.setContent(position, 1); } else { // System.out.println("XianChangAdd 没有内容了"); adapter.setContent(position, 0); } position++; } }
@Override public void onClick(View v) { // 动态初始化List,因为无法再以开始确定item的个数 List<Map<String, Object>> mItem = new ArrayList<Map<String, Object>>(); List<Map<String, Object>> mItem2 = new ArrayList<Map<String, Object>>(); mList.add(mItem); mUploadList.add(mItem2); int count = list.size(); if (count == 0) { list.add("第" + (count + 1) + "组"); } else { // count != 0; if ((mList.get(count - 1).size()) != 0) { // 只需要判断最后一个条目里面有没有内容即可 list.add("第" + (count + 1) + "组"); } else { Toast.makeText(DiXianActivity.this, "请先添加照片", Toast.LENGTH_SHORT).show(); } } adapter.notifyDataSetChanged(); }
private void getDataFromDB() { pDao = new PlanTaskDao(DiXianActivity.this); if (pDao != null) { lastDixianCount = pDao.getLastDixian(tid); counts = new int[lastDixianCount]; mContentCount = new int[lastDixianCount]; list.clear(); mList.clear(); mUploadList.clear(); for (int i = 0; i < lastDixianCount; i++) { // 判断每个条目里面是否有内容 list.add("第" + (i + 1) + "组"); } for (int i = 0; i < lastDixianCount; i++) { List<Map<String, Object>> mItem = new ArrayList<Map<String, Object>>(); mList.add(mItem); } for (int i = 0; i < lastDixianCount; i++) { List<Map<String, Object>> mItem = new ArrayList<Map<String, Object>>(); mUploadList.add(mItem); } } adapter.notifyDataSetChanged(); // 修正第二级目录id chenqiang data = AttachmentDatabase.instance(this) // 数据库中的url为文件名 .query( "SELECT * from tb_task_attachment where task_id = " + tid + " AND (url LIKE '" + tid + "/" + (secondId) + "/" + 3 + "%' or url LIKE '" + tid + "\\" + (secondId) + "/" + 3 + "%' or url LIKE '" + tid + "//" + (secondId) + "/" + 3 + "%' or url LIKE '" + tid + "\\\\" + (secondId) + "/" + 3 + "%')"); if (data != null) { // String fileCount = data.get("records_num"); for (int i = 0; i < Integer.parseInt(data.get("records_num")); i++) { Log.v( "login", data.get("id_" + i) + ":" + data.get("url_" + i) + ":" + data.get("status_" + i) + ":" + data.get("task_id_" + i) + ":" + data.get("dixian_" + i)); // String standard = data.get("standard_" + i); GpsDao gpsDao = new GpsDao(this); GPS gps = gpsDao.getHistory(data.get("historygps_" + i)); // 从数据库中获取gps信息 MyGPS mGPS = new MyGPS( gps.getOllectionTime(), Double.valueOf(gps.getLongitude()), Double.valueOf(gps.getLatitude()), Float.valueOf(gps.getAccuracy()), Double.valueOf(gps.getHeight()), Float.valueOf(gps.getSpeed()), gps.getCoordinate()); String name = data.get("url_" + i); String mediaName1 = name.replace("\\", File.separator); // 把所有的\替换成/ String mediaName = mediaName1.substring(mediaName1.lastIndexOf("/") + 1); String filePath = XianChangAdd.DownloadfileFolder + mediaName; // 附件信息 Map<String, Object> mMap1 = new HashMap<String, Object>(); mMap1.put("gps", mGPS); mMap1.put("path", filePath); mMap1.put("time", gps.getOllectionTime()); // 传递附件的时间 mMap1.put("pathContainsTid", XianChangAdd.DownloadfileFolder + mediaName1); String path1 = (String) mMap1.get( "pathContainsTid"); // storage/emulated/0/nercms-Schedule/DownloadAttachments/356/4/aq2016_06_03_143336.jpg String path = path1.replace("//", File.separator); int itemId = path.lastIndexOf("/"); String name1 = path.substring(itemId + 1); String tmp[] = name1.split("-"); String attId = tmp[0].substring(1); int attId1 = Integer.parseInt(attId); mMap1.put("index", counts[attId1 - 1] + ""); counts[attId1 - 1]++; mList.get(attId1 - 1).add(mMap1); mUploadList.get(attId1 - 1).add(mMap1); } } }