Skip to content

Commit d5e117e

Browse files
committed
Tune AddPersonFragment
1 parent 424fdea commit d5e117e

5 files changed

Lines changed: 20 additions & 28 deletions

File tree

‎app/src/main/java/com/example/yoga/sqliteexample/Fragment/AddPersonFragment.java‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.view.View;
1010
import android.view.View.OnClickListener;
1111
import android.view.ViewGroup;
12+
import android.view.inputmethod.InputMethodManager;
1213
import android.widget.Button;
1314
import android.widget.EditText;
1415
import android.widget.TextView;
@@ -22,7 +23,7 @@
2223
public 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;

‎app/src/main/java/com/example/yoga/sqliteexample/MainPage.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import android.view.Menu;
1515
import android.view.MenuItem;
1616
import android.view.View;
17+
import android.widget.Toast;
1718

1819
import com.example.yoga.sqliteexample.Adapter.BillRecyclerViewAdapter;
1920
import com.example.yoga.sqliteexample.Fragment.*;
@@ -255,7 +256,7 @@ public void setBillDetailFragment(int bill_id) {
255256
billDetailFragment.setBill_id(bill_id);
256257
FragmentTransaction ft = getFragmentManager().beginTransaction();
257258
ft.replace(R.id.content_frame, billDetailFragment);
258-
ft.addToBackStack("Bill Details");
259+
ft.addToBackStack("List Bill");
259260
ft.commit();
260261

261262
actionBar.setTitle("Bill Details");
@@ -332,6 +333,8 @@ public void floatingActionButtonOnClick(View view) {
332333
} else if (f instanceof BillDetailFragment) {
333334
Log.d(TAG, "BillDetailFragment");
334335
setAddItemFragment(BillDetailFragment.bill_id);
336+
} else {
337+
Toast.makeText(this, "Cannot add anything here!", Toast.LENGTH_SHORT).show();
335338
}
336339

337340
}

‎app/src/main/res/layout/fragment_add_person.xml‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,4 @@
3737
android:id="@+id/button_add_person_add"
3838
android:text="@string/add_to_db" />
3939

40-
<LinearLayout
41-
android:layout_width="match_parent"
42-
android:layout_height="wrap_content"
43-
android:orientation="horizontal">
44-
<TextView
45-
android:text="Status: "
46-
android:layout_width="wrap_content"
47-
android:layout_height="wrap_content"
48-
android:id="@+id/textView_add_person_status_prefix" />
49-
50-
<TextView
51-
android:text="Startup"
52-
android:layout_width="match_parent"
53-
android:layout_height="wrap_content"
54-
android:id="@+id/textView_add_person_status" />
55-
</LinearLayout>
56-
5740
</LinearLayout>
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
android:orientation="vertical"
3+
android:orientation="horizontal"
44
android:layout_width="match_parent"
55
android:layout_height="wrap_content">
66
<TextView
77
android:id="@+id/textView_itemListAdapter_itemName"
8-
android:layout_width="match_parent"
8+
android:layout_weight="1"
9+
android:layout_width="0dp"
910
android:layout_height="wrap_content"
1011
android:text="ItemName" />
1112

1213
<TextView
1314
android:id="@+id/textView_itemListAdapter_price"
14-
android:layout_width="match_parent"
15+
android:layout_weight="1"
16+
android:layout_width="0dp"
1517
android:layout_height="wrap_content"
1618
android:text="Price" />
1719
</LinearLayout>

‎app/src/main/res/values/strings.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<string name="navigation_drawer_close">Close navigation drawer</string>
66

77
<string name="action_settings">Settings</string>
8-
<string name="add_to_db">Add to Db</string>
8+
<string name="add_to_db">Add Person</string>
99
<string name="title_activity_bill_details">BillDetailsActivity</string>
1010
<string name="website_link">https://gges5110.github.io</string>
1111
</resources>

0 commit comments

Comments
 (0)