@@ -174,6 +174,21 @@ public void onClick(View v) {
174174 String first_list_itemText = first_list_item .getText ().toString ().trim ();
175175 String second_list_itemText = second_list_item .getText ().toString ().trim ();
176176
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+
177192 MatchModel temp = new MatchModel (first_list_itemText , second_list_itemText );
178193 matchData .add (temp );
179194 adapter .notifyDataSetChanged ();
@@ -303,6 +318,23 @@ public void onClick(View v) {
303318 String first_list_itemText = first_list_item .getText ().toString ().trim ();
304319 String second_list_itemText = second_list_item .getText ().toString ().trim ();
305320
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+
306338 data .setMatchA (first_list_itemText );
307339 data .setMatchB (second_list_itemText );
308340
@@ -351,7 +383,7 @@ public void restoreItem(Activity activity, int position, Object object) {
351383 }
352384 }else {
353385 if (object instanceof MatchModel ) {
354- MatchModel matchModel = (MatchModel ) object ;
386+ MatchModel matchModel = (MatchModel ) object ;
355387 if (matchModel != null ) {
356388 matchData .add (position , matchModel );
357389 adapter .notifyDataSetChanged ();
@@ -430,4 +462,4 @@ private void setEmptyView(Activity activity) {
430462 activity .findViewById (R .id .empty ).setVisibility (View .GONE );
431463 }
432464 }
433- }
465+ }
0 commit comments