fragment

Use Single Fragment in Multiple tabs of ViewPager

半城伤御伤魂 提交于 2019-12-21 02:52:09
问题 I am using ViewPager to slide left and right, I have also added the tabs, The number of tabs is depends on the server data, So, I cannot make the number of tabs as Fixed. To do this I used only Single Fragment and a RecyclerView to display JSON Data in the recyclerView. When First app launches, the data which should be shown in 2nd tab is getting displayed in 1st Tab itself. After I swipe to 3rd Tab and come Back again to 1st Tab, then the data is displaying correctly. It is as same as

Android - Headers categories in PreferenceActivity with PreferenceFragment

微笑、不失礼 提交于 2019-12-21 01:45:33
问题 I would like to display a preference screen like the one in the Android settings app : using headers, PreferenceActivity, PreferenceFragment and headers categories. I wan't this result on a tablet : And this one on a smartphone : It works if I just use the basic headers, but if I try to add categories, it works on the smartphone, and crash on the tablet, where I get the exception "java.lang.NullPointerException: name == null" : FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start

Android SDK error: Trying instantiate a class that is not a fragment

只愿长相守 提交于 2019-12-20 18:02:08
问题 I am hardly trying to create a simple application with a top menu and a changeable view below (by pressing the buttons in the menu fragment we change the view of the fragment below). So, I have 2 fragments inside the main view but when trying to run the application in the emulator I get an error like: Cause by android.app (bla bla bla, piece of crap Eclipse doesn't even allow copying the errors): Trying to instantiate a class com.example.android.topmenu that is not a fragment So, these are my

ViewPager+Fragment动态刷新问题

血红的双手。 提交于 2019-12-20 12:55:32
在我们的项目开发中会经常使用到ViewPager+Fragment来实现特定的UI效果,但是当Fragment需要动态增加,删除过内容变更时,会出现Fragment页面刷新失效的情况 如下: @BindView(R.id.viewpager) ViewPager viewpager; List<MyFragment> fragments = new ArrayList<>(); private void setupViewPager(List<String> list_key) { fragments.clear(); for (int i = 0; i < list_key.size(); i++) { fragments.add(MyFragment.newInstance(list_key.get(i))); } viewpager.setAdapter(new MyPagerAdapter(getChildFragmentManager(), fragments)); viewpager.setOffscreenPageLimit(2); } class MyPagerAdapter extends FragmentPagerAdapter { private List<MyFragment> fragments; public MyPagerAdapter

Tab content disappeared after change page

╄→尐↘猪︶ㄣ 提交于 2019-12-20 12:31:08
问题 I have a weird issue with my Tab (TabHost or TabContent) in my Fragment that contains a ViewPager. The problem is that when I change the page, then I turn back to the fragment with tab and viewPager, my content or view disappeared. -> Here's my code for TabFragment package com.halo.mobi.fragment; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.support.v4.app.Fragment; import android

insert and remove fragments into viewpager properly

天涯浪子 提交于 2019-12-20 10:09:37
问题 I'm making an adroid application with viewpager and fragments. I want to make an option to add or remove fragment pages to the pager dynamically. I have a custom FragmentPagerAdapter: public class MyAdapter extends FragmentPagerAdapter implements TitleProvider{ protected final List<PageFragment> fragments; /** * @param fm * @param fragments */ public MyAdapter(FragmentManager fm, List<PageFragment> fragments) { super(fm); this.fragments = fragments; } public void addItem(PageFragment f){

Fragment lifecycle with respect to it's activity

五迷三道 提交于 2019-12-20 09:29:47
问题 Situation My activity waits on an Async operation and after it hears back from async operation, it needs to pass information to 2 fragments inside it. Requirement 1. Both fragments need their onCreateView calls to be done for them to have their layouts loaded, 2. They need for themselves to be attached to their activity so that getActivity() works. I wrote a setData() method in both the fragments and am looking for the "correct" place in the activity's lifecycle to invoke them. onCreate() of

Listview item not Display in the Fragment Android

余生长醉 提交于 2019-12-20 06:23:40
问题 I have Navigation Drawer with Fragment. I want to Open Fragment on Navigation Drawer. No any Error comes in code but Listview Item Not Display in Fragment. Only Blank Page Display. Following Code. Plzz Help Me. fragment_blank_fragment_trip2.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.example

Android studio: how add tabs with ViewPager

落爺英雄遲暮 提交于 2019-12-20 04:31:33
问题 I want to add in a fragment a tab with pagerview (scrollable). public class MyFragment extends Fragment { private FragmentTabHost tabHost; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { tabHost = new FragmentTabHost(getActivity()); tabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent); tabHost.addTab(tabHost.newTabSpec("one").setIndicator("One"), OneFragment.class, null); tabHost.addTab(tabHost.newTabSpec(

Fragment has not been attached yet

非 Y 不嫁゛ 提交于 2019-12-20 04:29:05
问题 After reading posts on this exception, I can't understand what I need to do to correct this error. Besides, I can't even reproduce it... This happens sometimes on some devices but I don't understand how... my logs : Fatal Exception: java.lang.IllegalStateException Fragment a has not been attached yet my.app.HostFragment.addFragment HostFragment class : fun addFragment(fragment: Fragment) { childFragmentManager.beginTransaction() .add(R.id.fragment_root_container, fragment) .addToBackStack