|
13 | 13 | import android.util.Log; |
14 | 14 | import android.view.Menu; |
15 | 15 | import android.view.MenuItem; |
| 16 | +import android.view.View; |
16 | 17 |
|
17 | 18 | import com.example.yoga.sqliteexample.Adapter.BillRecyclerViewAdapter; |
18 | 19 | import com.example.yoga.sqliteexample.Fragment.*; |
@@ -153,18 +154,18 @@ public void displayView(int viewId) { |
153 | 154 | String title = getString(R.string.app_name); |
154 | 155 |
|
155 | 156 | switch (viewId) { |
156 | | - case R.id.nav_add_person: |
157 | | - fragment = new AddPersonFragment(); |
158 | | - title = "Add Person"; |
159 | | - break; |
160 | | - case R.id.nav_add_bill: |
161 | | - fragment = new AddBillFragment(); |
162 | | - title = "Add Bill"; |
163 | | - break; |
164 | | - case R.id.nav_add_item: |
165 | | - // fragment = new AddItemFragment(); |
166 | | - // title = "Add item"; |
167 | | - break; |
| 157 | +// case R.id.nav_add_person: |
| 158 | +// fragment = new AddPersonFragment(); |
| 159 | +// title = "Add Person"; |
| 160 | +// break; |
| 161 | +// case R.id.nav_add_bill: |
| 162 | +// fragment = new AddBillFragment(); |
| 163 | +// title = "Add Bill"; |
| 164 | +// break; |
| 165 | +// case R.id.nav_add_item: |
| 166 | +// // fragment = new AddItemFragment(); |
| 167 | +// // title = "Add item"; |
| 168 | +// break; |
168 | 169 | case R.id.nav_list_person: |
169 | 170 | fragment = new ListPersonFragment(); |
170 | 171 | title = "List Person"; |
@@ -230,4 +231,43 @@ public void setBillDetailFragment() { |
230 | 231 | actionBar.setTitle("Bill Details"); |
231 | 232 | displayHomeIcon(false); |
232 | 233 | } |
| 234 | + |
| 235 | + private void setAddBillFragment() { |
| 236 | + AddBillFragment addBillFragment = new AddBillFragment(); |
| 237 | + FragmentTransaction ft = getFragmentManager().beginTransaction(); |
| 238 | + ft.replace(R.id.content_frame, addBillFragment); |
| 239 | + ft.addToBackStack("List Bill"); |
| 240 | + ft.commit(); |
| 241 | + |
| 242 | + actionBar.setTitle("Add Bill"); |
| 243 | + displayHomeIcon(false); |
| 244 | + } |
| 245 | + |
| 246 | + private void setAddPersonFragment() { |
| 247 | + AddPersonFragment addPersonFragment = new AddPersonFragment(); |
| 248 | + FragmentTransaction ft = getFragmentManager().beginTransaction(); |
| 249 | + ft.replace(R.id.content_frame, addPersonFragment); |
| 250 | + ft.addToBackStack("List Person"); |
| 251 | + ft.commit(); |
| 252 | + |
| 253 | + actionBar.setTitle("Add Person"); |
| 254 | + displayHomeIcon(false); |
| 255 | + } |
| 256 | + |
| 257 | + public void floatingActionButtonOnClick(View view) { |
| 258 | + Log.d(TAG, "floatingActionButtonOnClick"); |
| 259 | + // Check which fragment it is in. |
| 260 | + Fragment f = getFragmentManager().findFragmentById(R.id.content_frame); |
| 261 | + if (f instanceof ListBillFragment) { |
| 262 | + Log.d(TAG, "ListBillFragment"); |
| 263 | + // Replace current fragment with AddBillFragment |
| 264 | + setAddBillFragment(); |
| 265 | + |
| 266 | + } else if (f instanceof ListPersonFragment) { |
| 267 | + Log.d(TAG, "ListPersonFragment"); |
| 268 | + // Replace current fragment with AddPersonFragment |
| 269 | + setAddPersonFragment(); |
| 270 | + } |
| 271 | + |
| 272 | + } |
233 | 273 | } |
0 commit comments