Android check null or empty string in Android

Use TextUtils.isEmpty( someString ) String myString = null; if (TextUtils.isEmpty(myString)) { return; // or break, continue, throw } // myString is neither null nor empty if this point is reached Log.i(“TAG”, myString); Notes The documentation states that both null and zero length are checked for. No need to reinvent the wheel here. A good practice … Read more

After the rotate, onCreate() Fragment is called before onCreate() FragmentActivity

You should not count on a valid Activity until the onActivityCreated() call in the Fragment’s life cycle. Called when the fragment’s activity has been created and this fragment’s view hierarchy instantiated. It can be used to do final initialization once these pieces are in place, such as retrieving views or restoring state. The exact reasons … Read more

Manage toolbar’s navigation and back button from fragment in android

Add a toolbar to your xml <android.support.v7.widget.Toolbar android:id=”@+id/toolbar” android:layout_width=”match_parent” android:layout_height=”?attr/actionBarSize” android:background=”?attr/colorPrimary” android:theme=”@style/ThemeOverlay.AppCompat.ActionBar” app:popupTheme=”@style/ThemeOverlay.AppCompat.Light”> <TextView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Fragment title”/> </android.support.v7.widget.Toolbar> Then inside your onCreateView method in the Fragment: Toolbar toolbar = view.findViewById(R.id.toolbar); toolbar.setNavigationIcon(R.drawable.ic_back_button); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getActivity().onBackPressed(); } });

Hide/Show Action Bar Option Menu Item for different fragments

Try this… You don’t need to override onCreateOptionsMenu() in your Fragment class again. Menu items visibility can be changed by overriding onPrepareOptionsMenu() method available in Fragment class. @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true); } @Override public void onPrepareOptionsMenu(Menu menu) { menu.findItem(R.id.action_search).setVisible(false); super.onPrepareOptionsMenu(menu); }

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)