Custom attributes in Android fragments

The Link for Support4Demos is changed or can be changed so posting the complete solution. Here it goes. Create attrs.xml file in res/values folder. Or add the below content if file already exists. <?xml version=”1.0″ encoding=”utf-8″?> <resources> <declare-styleable name=”MyFragment”> <attr name=”my_string” format=”string”/> <attr name=”my_integer” format=”integer”/> </declare-styleable> Override the onInflate delegate of fragment and read attributes … Read more

Android – How to change fragments in the Navigation Drawer

Follow This link!! for more details and use private class DrawerItemClickListener implements ListView.OnItemClickListener { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { selectItem(position); } } and private void selectItem(int position) { FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction ft = fragmentManager.beginTransaction(); switch (position) { case 0: ft.replace(R.id.content_frame, new Fragment1, Constants.TAG_FRAGMENT).commit(); break; case 1: … Read more

Fragment inner class should be static

Non static inner classes do hold a reference to their parent classes. The problem with making a Fragment inner class non-static is that you always hold a reference to the Activity. The GarbageCollector cannot collect your Activity. So you can ‘leak’ the Activity if for example the orientation changes. Because the Fragment might still live … Read more

On showing dialog I get “Can not perform this action after onSaveInstanceState”

This is common issue. We solved this issue by overriding show() and handling exception in DialogFragment extended class public class CustomDialogFragment extends DialogFragment { @Override public void show(FragmentManager manager, String tag) { try { FragmentTransaction ft = manager.beginTransaction(); ft.add(this, tag); ft.commit(); } catch (IllegalStateException e) { Log.d(“ABSDIALOGFRAG”, “Exception”, e); } } } Note that applying … Read more

Angular2 How to navigate to certain section of the page identified with an id attribute

Angular 2: I would prefer to go with scrollIntoView() method scrollIntoView. It would provide smooth scrolling transition effect in the browser. HTML Code <div #info id=”info”> <h3>Info</h3> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p> </div> <div #structure id=”structure”> <h3>Structure</h3> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p> </div> <li> <ul materialize=”collapsible” class=”collapsible” data-collapsible=”accordion”> <li><a … Read more

Adding Tab inside Fragment In Android?

Try to do this to handle the Tabs: public class MainFragment extends Fragment { private FragmentTabHost mTabHost; //Mandatory Constructor public MainFragment() { } public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_tabs,container, false); mTabHost = (FragmentTabHost)rootView.findViewById(android.R.id.tabhost); mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent); mTabHost.addTab(mTabHost.newTabSpec(“fragmentb”).setIndicator(“Fragment B”), FragmentB.class, null); mTabHost.addTab(mTabHost.newTabSpec(“fragmentc”).setIndicator(“Fragment … Read more

tech