使用带有ViewPager
的{{1}}时,我收到一个奇怪的OutOfMemoryError。
片段只有一个根元素,而Activity是非常基本的,因为我试图将它剥离到裸骨以试图找出它发生的位置。
它似乎发生在片段中FragmentPagerAdapter
之后,但似乎无法找到罪魁祸首。
非常感谢你的帮助。
活动
onCreateView()
XML
public class Activity_Content_Dialog extends AppCompatActivity {
private SlideshowAdapter _slideShowAdapter;
private ViewPager _viewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_content_dialog);
_slideShowAdapter = new SlideshowAdapter(getSupportFragmentManager());
_viewPager = (ViewPager) findViewById(R.id.viewPager);
_viewPager.setAdapter(_slideShowAdapter);
}
}
片段
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/content_dialog_activity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
XML
public class Fragment_Empty extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.empty_frag,container);
return view;
}
}
寻呼机适配器
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android" />
最后,这是错误消息
public class SlideshowAdapter extends FragmentPagerAdapter {
public SlideshowAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
return new Fragment_Empty();
}
@Override
public int getCount() {
return 2;
}
}
答案 0 :(得分:0)
改变 View view = inflater.inflate(R.layout.empty_frag,container); 至 View view = inflater.inflate(R.layout.empty_frag,container,false);