Channel: Safaa Al-Hayali
Category: Howto & Style
Tags: android app developmentandroidandroid studiomenu androidhow to androidandroid tutorialmobile android programmingjavatoolbar androidsafaa al-hayaliprogramming languageactionbar androidtutorialsaf3al2alearn android
Description: Toolbar or Action-bar or Menu, is quite useful feature you have to take benefit from it, by creating action or menu items to do some action in your app, or you can use it for navigation and for displaying logo or your app brand. so, in this video you'll learn about toolbar... and at the end of this video you'll face a small issue in updating the parent activity, I've already explained that in this tutorial: youtu.be/geql_wwXIhw but, if you can't solve it here is the solution: ListOfUsers.java: @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()){ case R.id.new_user: Intent intent = new Intent(this, NewUser.class); startActivityForResult(intent,2); return true; default: return super.onOptionsItemSelected(item); } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(resultCode == RESULT_OK){ if(requestCode == 1){ if(data!=null){ //mUsersAdapter.notifyDataSetChanged(); String action = data.getStringExtra("action"); if(action.equals("update")){ mUsersAdapter.notifyItemChanged(mPosition); }else if(action.equals("delete")){ mUsersAdapter.notifyItemRemoved(mPosition); } } }else if(requestCode == 2){ mUsersAdapter.notifyItemInserted(mUsers.size()); } } } ======================================== NewUser.java: mAdd_btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setResult(RESULT_OK,null); User user = new User(); user.setFirstname(mFirstname_editTxt.getText().toString()); user.setEmail(mEmail_editTxt.getText().toString()); UsersBase.get().newUser(user); Toast.makeText(NewUser.this,"New user has been added to the list", Toast.LENGTH_LONG).show(); mFirstname_editTxt.setText(""); mEmail_editTxt.setText(""); } });