99import android .view .View ;
1010import android .view .View .OnClickListener ;
1111import android .view .ViewGroup ;
12+ import android .view .inputmethod .InputMethodManager ;
1213import android .widget .Button ;
1314import android .widget .EditText ;
1415import android .widget .TextView ;
2223public class AddPersonFragment extends Fragment {
2324 Button button_add_person_add ;
2425 EditText editText_add_person_name , editText_add_person_email ;
25- TextView textView_add_person_status ;
26+ Activity activity ;
2627
2728 public interface AddPersonInterface {
2829 long createPerson (Person p );
@@ -33,7 +34,7 @@ public interface AddPersonInterface {
3334 @ Override
3435 public void onAttach (Context context ) {
3536 super .onAttach (context );
36- Activity activity ;
37+
3738
3839 if (context instanceof Activity ) {
3940 activity = (Activity ) context ;
@@ -57,7 +58,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
5758 button_add_person_add = (Button ) myView .findViewById (R .id .button_add_person_add );
5859 editText_add_person_email = (EditText ) myView .findViewById (R .id .editText_add_person_email );
5960 editText_add_person_name = (EditText ) myView .findViewById (R .id .editText_add_person_name );
60- textView_add_person_status = (TextView ) myView .findViewById (R .id .textView_add_person_status );
6161
6262 button_add_person_add .setOnClickListener (new OnClickListener () {
6363 @ Override
@@ -68,10 +68,14 @@ public void onClick(View v) {
6868 Person p = new Person ();
6969 p .setName (editText_add_person_name .getText ().toString ());
7070 p .setEmail (editText_add_person_email .getText ().toString ());
71+ mListener .createPerson (p );
7172
72- long status = mListener .createPerson (p );
73-
74- textView_add_person_status .setText (String .valueOf (status ));
73+ // Check if no view has focus:
74+ View view = activity .getCurrentFocus ();
75+ if (view != null ) {
76+ InputMethodManager imm = (InputMethodManager ) activity .getSystemService (Context .INPUT_METHOD_SERVICE );
77+ imm .hideSoftInputFromWindow (view .getWindowToken (), 0 );
78+ }
7579 }
7680 });
7781 return myView ;
0 commit comments