我有一個模型:在ArrayList中獲取索引第一個和最後一個項目?
public class Unprocessed_DistanceTime_D {
private String lat;
private String lng;
private String date;
private String time;
private String counts;
private String userCode;
public String getLat() {
return lat;
}
public void setLat(String lat) {
this.lat = lat;
}
public String getLng() {
return lng;
}
public void setLng(String lng) {
this.lng = lng;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getCounts() {
return counts;
}
public void setCounts(String counts) {
this.counts = counts;
}
public String getUserCode() {
return userCode;
}
public void setUserCode(String userCode) {
this.userCode = userCode;
}
}
而且我填補我與波紋管的數據模型:
DATE TIME LAT LNG COUNT
1395/04/26 12:13:44 34.6117392 50.8548033 7
1395/04/26 12:13:49 34.6117392 50.8548033 7
1395/04/26 12:13:58 34.6117392 50.8548033 7
1395/04/26 12:14:00 34.6117392 50.8548033 7
1395/04/26 12:14:22 34.6117392 50.8548033 7
1395/04/26 12:14:44 34.6117392 50.8548033 7
1395/04/26 12:14:49 34.6117392 50.8548033 7
1395/04/26 12:14:58 34.6113533 50.8551068 27
1395/04/26 12:14:58 34.6113533 50.8551068 27
1395/04/26 12:15:00 34.6113533 50.8551068 27
1395/04/26 12:15:22 34.6113533 50.8551068 27
1395/04/26 12:15:35 34.6322184 50.8596414 9
1395/04/26 12:15:44 34.6113533 50.8551068 27
1395/04/26 12:15:49 34.6113533 50.8551068 27
1395/04/26 12:15:58 34.6113533 50.8551068 27
1395/04/26 12:15:58 34.6113533 50.8551068 27
1395/04/26 12:16:00 34.6113533 50.8551068 27
1395/04/26 12:16:09 34.6322184 50.8596414 9
1395/04/26 12:16:22 34.6113533 50.8551068 27
1395/04/26 12:16:44 34.6113533 50.8551068 27
1395/04/26 12:16:49 34.6113533 50.8551068 27
1395/04/26 12:16:58 34.6113533 50.8551068 27
1395/04/26 12:16:58 34.6113533 50.8551068 27
1395/04/26 12:17:00 34.6113533 50.8551068 27
1395/04/26 12:17:22 34.6113533 50.8551068 27
1395/04/26 12:17:44 34.6113533 50.8551068 27
1395/04/26 12:17:49 34.6113533 50.8551068 27
1395/04/26 12:17:58 34.6113533 50.8551068 27
1395/04/26 12:17:58 34.6113533 50.8551068 27
1395/04/26 12:18:00 34.6113533 50.8551068 27
1395/04/26 12:18:22 34.6113533 50.8551068 27
1395/04/26 12:18:38 34.6322184 50.8596414 9
1395/04/26 12:18:44 34.6113533 50.8551068 27
1395/04/26 12:18:49 34.6113533 50.8551068 27
1395/04/26 12:18:51 34.6322184 50.8596414 9
1395/04/26 12:18:58 34.6113533 50.8551068 27
1395/04/26 12:18:58 34.6113533 50.8551068 27
1395/04/26 12:19:00 34.6113533 50.8551068 27
1395/04/26 12:19:01 34.6113415 50.8562128 22
1395/04/26 12:19:22 34.6113415 50.8562128 22
1395/04/26 12:19:44 34.6113415 50.8562128 22
1395/04/26 12:19:49 34.6113415 50.8562128 22
1395/04/26 12:19:58 34.6113415 50.8562128 22
1395/04/26 12:19:58 34.6113415 50.8562128 22
1395/04/26 12:20:00 34.6113415 50.8562128 22
1395/04/26 12:20:01 34.6113415 50.8562128 22
1395/04/26 12:21:41 34.6322184 50.8596414 9
1395/04/26 12:22:32 34.6113415 50.8562128 22
1395/04/26 12:22:36 34.6322184 50.8596414 9
1395/04/26 12:25:00 34.6113415 50.8562128 22
1395/04/26 12:25:04 34.6113415 50.8562128 22
1395/04/26 12:25:13 34.6113415 50.8562128 22
1395/04/26 12:25:13 34.6113415 50.8562128 22
1395/04/26 12:25:16 34.6113415 50.8562128 22
1395/04/26 12:25:16 34.6113415 50.8562128 22
1395/04/26 12:25:37 34.6113415 50.8562128 22
1395/04/26 12:25:37 34.6322184 50.8596414 9
1395/04/26 12:26:00 34.6113415 50.8562128 22
1395/04/26 12:26:04 34.6113415 50.8562128 22
1395/04/26 12:26:13 34.6113415 50.8562128 22
1395/04/26 12:26:20 34.6113415 50.8562128 22
1395/04/26 12:26:38 34.6113415 50.8562128 22
1395/04/26 12:26:38 34.6322184 50.8596414 9
1395/04/26 12:26:39 34.6113415 50.8562128 22
1395/04/26 12:29:46 34.6322184 50.8596414 9
而且我寫的波紋管代碼,但不要爲我工作了獲得第一和最後的索引項目是相同的,我使用你的代碼,但我不能得到真實的答案。 我的數據是排序基準時間,我不喜歡改變它,我應該在不改變的情況下處理這些數據。
我的代碼是在這裏:
public class ComputeDetailMoreActivity_E extends AppCompatActivity {
Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_computedetailmore);
int count = 1;
int X = 2;
boolean flag = true;
int index1 = -1;
int index2 = -1;
Integer counter = 0;
for (int i = 0; i < listCDM.size() - 1; i++) {
if (listCDM.get(i).getDate().equalsIgnoreCase(listCDM.get(count).getDate()) &&
listCDM.get(i).getLat().equalsIgnoreCase(listCDM.get(count).getLat()) &&
listCDM.get(i).getLng().equalsIgnoreCase(listCDM.get(count).getLng()) &&
listCDM.get(i).getCounts().equalsIgnoreCase(listCDM.get(count).getCounts())) {
if (flag) {
index1 = i;
flag = false;
counter++;
}
} else {
if (X < listCDM.size()) {
if (!listCDM.get(count).getLat().equalsIgnoreCase(listCDM.get(X).getLat()) &&
!listCDM.get(count).getLng().equalsIgnoreCase(listCDM.get(X).getLng()) &&
!listCDM.get(count).getCounts().equalsIgnoreCase(listCDM.get(X).getCounts())||
!listCDM.get(count).getDate().equalsIgnoreCase(listCDM.get(X).getDate())) {
Log.i("ADFASFEWRWE", "C : " + listCDM.get(X).getCounts() + "**" +
listCDM.get(X).getTime());
index2 = i;
Log.i("ASDASRDWE",i + "");
int error = count;
counter = 2;
}
if (listCDM.get(count).getLat().equalsIgnoreCase(listCDM.get(X).getLat()) &&
listCDM.get(count).getLng().equalsIgnoreCase(listCDM.get(X).getLng()) &&
listCDM.get(count).getCounts().equalsIgnoreCase(listCDM.get(X).getCounts()) &&
listCDM.get(count).getDate().equalsIgnoreCase(listCDM.get(X).getDate())) {
index2 = i;
flag = true;
counter++;
}
Log.i("RRTTGGTT", counter + "");
if (counter == 2) {
Log.i("ASDWERWEDAVVGG", index1 + " : " + index2);
flag = true;
counter = 0;
index1 = -1;
index2 = -1;
}
}
}
count++;
X++;
}
}
}
我出來說就是:
7 : 6
7 : 10
12 : 16
18 : 30
32 : 33
38 : 45
-1 : 46
-1 : 47
49 : 55
57 : 61
-1 : 62
你的問題不清楚,請描述你需要的東西 – Smit
請提供你到目前爲止嘗試過的代碼。 SO不是給網站的代碼。它相當於一個解決問題的平臺 –
這看起來像一個純粹的Java問題,因此這裏不需要Android標籤。 – EJK