@@ -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
@@ -352,7 +384,7 @@ public void restoreItem(Activity activity, int position, Object object) {
352384 }
353385 }else {
354386 if (object instanceof MatchModel ) {
355- MatchModel matchModel = (MatchModel ) object ;
387+ MatchModel matchModel = (MatchModel ) object ;
356388 if (matchModel != null ) {
357389 matchData .add (position , matchModel );
358390 adapter .notifyDataSetChanged ();
@@ -432,4 +464,4 @@ private void setEmptyView(Activity activity) {
432464 activity .findViewById (R .id .empty ).setVisibility (View .GONE );
433465 }
434466 }
435- }
467+ }
0 commit comments