@@ -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
@@ -352,7 +384,7 @@ public void restoreItem(Activity activity, int position, Object object) {
352
384
}
353
385
}else {
354
386
if (object instanceof MatchModel ) {
355
- MatchModel matchModel = (MatchModel ) object ;
387
+ MatchModel matchModel = (MatchModel ) object ;
356
388
if (matchModel != null ) {
357
389
matchData .add (position , matchModel );
358
390
adapter .notifyDataSetChanged ();
@@ -432,4 +464,4 @@ private void setEmptyView(Activity activity) {
432
464
activity .findViewById (R .id .empty ).setVisibility (View .GONE );
433
465
}
434
466
}
435
- }
467
+ }
0 commit comments