Tag: android-fragments

How to implement onBackPressed() & intents in fragment?

I know that onBackPressed() is a method in activity but, I want to use the functionality in fragments such that when back button is pressed, it gets redirected to another activity via Intent. Is there any solution to this ? public class News_Events_fragment extends Fragment { ProgressDialog pd; ListView lv1; SharedPreferences sharedPreferences = null; int […]

“Content has view with id attribute 'android.r.id.list' that is not a ListView Class.” when create a list view in a fragment

Here is the problem. I have a list view, and it looks fine in the building, but it broke the error. Content has view with id attribute ‘android.r.id.list’ that is not a ListView Class. I haven’t added the listview into the XML, something like :@android:list, the reason I didn’t do that is I could find […]

Tabs of TabLayout not showing

I have a main activity, which hosts a fragment, which in turn hosts a TabLayout (with a ViewPager). The tab bar is shown, baut the tabs themselves are not shown. Here is my code in the main activity for displaying the host fragment: Fragment fragment = new BMITabsFragment(); FragmentManager fragmentManager = getSupportFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).addToBackStack(Constants.BMI_TABS_FRAGMENT).commit(); Here […]

How do I make a specific item in the navigation drawer to appear as selected?

I have been frustrated with this problem for quite a while, but I can’t seem to make an item in the navigation drawer to appear as selected neither programmatically nor when the user selects it. I am trying to achieve the following http://i.stack.imgur.com/PIHEm.png (I cannot post images yet) I have followed the example navigation drawer […]

Android View Pager Adapter shows empty screen

I am implementing Pager Adapter in a Fragment. When i load the screen First time, it works fine. If i switch to other fragment and goes to previous fragment again the it shows empty screen. If i swipe between different tap and move to first tab again then it shows data. I think on moving […]

When is onAttach called during the Fragment LifeCycle?

This question already has an answer here: Why is onAttach called before onCreate? 4 answers

Using nested fragment and animator object alongside

I have Fragment A which contains two fragments, Fragment B and Fragment C. I want to add fragment B to fragment A using getChildFragmentManager() then replace it with fragment C by card flip animation using this code getChildFragmentManager() .beginTransaction() .setCustomAnimations( R.animator.card_flip_right_in, R.animator.card_flip_right_out, R.animator.card_flip_left_in, R.animator.card_flip_left_out) .replace(R.id.fragment_new_word_container, new FragmentCardBack()) .addToBackStack(null) .commit(); Nested Fragments introduced in android 4.2 […]

How to Change Text Style in Preference Fragment

I have created Preference Screen with Text View.User can change Text view style like font,color,size in Preference screen.so it will displayed on Textview which i have created in Preference Screen.but its not working .If its preference Activity ,we can use setContentview,In fragments i don’t know how to pass the view.. public final class TestFragment2 extends […]

How to send data from Activity to Fragment

I know there are many topics about this here. I have also read documentation many times but I can’t find the best way to pass data from activity to fragment. I want to be able to show the results of my Searchable activity in two differents layouts (list and map) using swipe Views with tabs. […]

How to correctly create a Tablayout now that the Tabactivity is deprecated?

Since the introduction of Fragments the TabActivity is deprecated. The Hello Views TabLayout Tutorial however still uses the TabActivity and the API-Documentation has no clear answer on how to create a Tab Layout with Fragments instead of a TabActivity. How are you building Tablayouts now that the TabActivity is deprecated?

Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.