@@ -174,6 +174,21 @@ public void onClick(View v) {
174
174
String first_list_itemText = first_list_item .getText ().toString ().trim ();
175
175
String second_list_itemText = second_list_item .getText ().toString ().trim ();
176
176
177
+ if (matchData .size () > 0 ) {
178
+ for (int i = 0 ; i < matchData .size (); i ++) {
179
+ if (first_list_itemText .equals (matchData .get (i ).getMatchA ()) || first_list_itemText .equals (matchData .get (i ).getMatchB ())) {
180
+ first_list_item .requestFocus ();
181
+ first_list_item .setError ("Option already inserted in list" );
182
+ return ;
183
+ }
184
+ if (second_list_itemText .equals (matchData .get (i ).getMatchA ()) || second_list_itemText .equals (matchData .get (i ).getMatchB ())) {
185
+ second_list_item .requestFocus ();
186
+ second_list_item .setError ("Option already inserted in list" );
187
+ return ;
188
+ }
189
+ }
190
+ }
191
+
177
192
MatchModel temp = new MatchModel (first_list_itemText , second_list_itemText );
178
193
matchData .add (temp );
179
194
adapter .notifyDataSetChanged ();
@@ -303,6 +318,23 @@ public void onClick(View v) {
303
318
String first_list_itemText = first_list_item .getText ().toString ().trim ();
304
319
String second_list_itemText = second_list_item .getText ().toString ().trim ();
305
320
321
+ if (matchData .size () > 0 ){
322
+ for (int i =0 ;i <matchData .size ();i ++){
323
+ if (i == position )
324
+ continue ;
325
+ if (first_list_itemText .equals (matchData .get (i ).getMatchA ()) || first_list_itemText .equals (matchData .get (i ).getMatchB ())) {
326
+ first_list_item .requestFocus ();
327
+ first_list_item .setError ("Option already inserted in the list" );
328
+ return ;
329
+ }
330
+ if (second_list_itemText .equals (matchData .get (i ).getMatchA ()) || second_list_itemText .equals (matchData .get (i ).getMatchB ())) {
331
+ second_list_item .requestFocus ();
332
+ second_list_item .setError ("Option already inserted in the list" );
333
+ return ;
334
+ }
335
+ }
336
+ }
337
+
306
338
data .setMatchA (first_list_itemText );
307
339
data .setMatchB (second_list_itemText );
308
340
@@ -351,7 +383,7 @@ public void restoreItem(Activity activity, int position, Object object) {
351
383
}
352
384
}else {
353
385
if (object instanceof MatchModel ) {
354
- MatchModel matchModel = (MatchModel ) object ;
386
+ MatchModel matchModel = (MatchModel ) object ;
355
387
if (matchModel != null ) {
356
388
matchData .add (position , matchModel );
357
389
adapter .notifyDataSetChanged ();
@@ -430,4 +462,4 @@ private void setEmptyView(Activity activity) {
430
462
activity .findViewById (R .id .empty ).setVisibility (View .GONE );
431
463
}
432
464
}
433
- }
465
+ }
0 commit comments