android-viewpager

Why is my fragment onCreate being called extensively whenever I page through my applications viewPager?

孤者浪人 提交于 2020-01-01 05:01:07
问题 I'm not quite understanding this fragment lifecycle business. I have a pretty standard 3 page horizontal slider view Pager layout for a "view details" section of my app. I start my app on the middle page of the three. My FragmentActivity sets the page to page 1. mPager.setCurrentItem(1); //default to center page, current data view fragment I've been using the FragmentStatePagerAdapter because using the FragmentPagerAdapter crashed my app at times, when coming back from a suspended state for

Android Scrollable Tabs + Swipe state when swiping

狂风中的少年 提交于 2020-01-01 03:45:11
问题 I'm trying to make an application with multiple Tabs. For each tab I'm using different fragments. And when I leaf through tabs the information in them is changing. How can I save the state of each tab when swiping? Code for example: MainActivity.java : package com.tabs.example; import java.util.Locale; import android.graphics.Color; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager;

View Pager as List View Row Item

戏子无情 提交于 2019-12-31 22:23:54
问题 I have a list view with 20 rows and I want to setup a view pager as each row in a list view. As the items coming in my row of the list view may one or more than one, and I want to show the list view row items using a view pager. For this I am using the following code: Custom Layout which is to be shown in the list view row (as the pager item) <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/inner_layout" android

How to change the current tab highlighter color in Android ViewPager?

倖福魔咒の 提交于 2019-12-31 12:57:10
问题 Here is my layout inside ViewPager . I would like to change the color of the current tab highlighter which is below the text. Actually it is showing in black color. But I don't know whether it is a color by default or not. And also I have one more doubt. If I use PagerTitleStrip this tab highlighter doesn't appear. Is there a way to bring that with titlestrip? Here is my layout: <android.support.v4.view.PagerTabStrip android:id="@+id/pager_title_strip" android:layout_width="match_parent"

IllegalStateException: <MyFragment> is not currently in the FragmentManager

微笑、不失礼 提交于 2019-12-31 08:34:34
问题 I know it sounds like a duplicate of FragmentStatePagerAdapter IllegalStateException: <MyFragment> is not currently in the FragmentManager but his solution isn't relevant to my case. I'm getting the following crash very rarely: java.lang.RuntimeException: Unable to pause activity {MyActivity}: ... Caused by: java.lang.IllegalStateException: Fragment MyFragment {40648258 id=0x7f070051} is not currently in the FragmentManager at android.support.v4.app.FragmentManagerImpl.putFragment(MT:516) at

How to properly handle screen rotation with a ViewPager and nested fragments?

拈花ヽ惹草 提交于 2019-12-31 08:28:42
问题 I've got this activity, which holds a fragment. This fragment layout consists of a view pager with several fragments (two, actually). When the view pager is created, its adapter is created, getItem gets called and my sub fragments are created. Great. Now when I rotate the screen, the framework handles the fragment re-creation, the adapter is created again in my onCreate from the main fragment, but getItem never gets called , so my adapter holds wrong references (actually nulls) instead of the

Grid layout within tabs

柔情痞子 提交于 2019-12-31 04:07:11
问题 I'm new to Android and therefore faced such problem. How can I change layout from: To: XML fragment_main: <RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen

How do i Swipe selected grid image in Full Screen

只谈情不闲聊 提交于 2019-12-31 03:49:12
问题 i created a grid-view image app, and i want to show selected image in image swipe. actually i implemented image swipe in my app but the problem is image swipe starts from 1st image not from selected image. example: if i choose 3rd image image swipe should starts from 3rd image not from 1st image. my code: MainActivity.java package com.td.gridview; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view

Fragment in ViewPager is not displaying anything in its RecyclerView on rotation

拜拜、爱过 提交于 2019-12-31 01:49:09
问题 I have 4 Fragments in a ViewPager that is integrated with a TabLayout. Each of those Fragments holds a RecyclerView because I'm displaying an unknown amount of list items. The items are loaded by date, so I have two buttons that let you change days, and then the appropriate data in the list items is loaded based on the date that is set. The buttons are part of the outer activity. Everything so far works perfectly BUT once I rotate the device the fragments don't load anything. Nothing is

How can I make my view pager more smooth?

纵饮孤独 提交于 2019-12-30 09:29:49
问题 I am using a view pager to show two fragments. One fragment contains a camera preview and the other one just a simple list view. The problem is, that the whole swipe experience is not as smooth as it should be. And I guess the reason for that is because the UI Thread has to handle the view pager, the camera and the list view all at once. Now, what can I do about that? What can I run in a background thread? Can I run the view pager in the background? 来源: https://stackoverflow.com/questions