Git Product home page Git Product logo

Comments (3)

ogaclejapan avatar ogaclejapan commented on August 29, 2024

Hi, @efimenkofedor

Yes, there is also a possibility that the null is returned.
It is written in REAME.

.instantiateItem() from until .destoryItem() is called it will be able to get the Fragment of page.

To initialize after the request?

@Override
public void run() {
    try {
        // answer
        final String json = "";

        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                adapter = new FragmentPagerItemAdapter(
                            getSupportFragmentManager(), FragmentPagerItems.with(this)
                            .add("tab1", fragment_tab_a.getClass(), new Bundler().putString("result", "1-ok").get())
                            .add("tab2", fragment_tab_b.getClass(), new Bundler().putString("result", "2-ok").get())
                            .add("tab3", fragment_tab_c.getClass(), new Bundler().putString("result", "3-ok").get())
                            .create());

                ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
                viewPager.setAdapter(adapter);

                SmartTabLayout viewPagerTab = (SmartTabLayout) findViewById(R.id.viewpagertab);
                viewPagerTab.setViewPager(viewPager);            

            }
        });
    } catch (Exception e) {
        //runOnUiThread(checkInternetConnection);
        e.printStackTrace();
    }
}

from smarttablayout.

JSONValidator avatar JSONValidator commented on August 29, 2024

Now I have so:

public class MainActivity extends AppCompatActivity {

    ViewPagerItemAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Thread thread = new Thread() {
            @Override
            public void run() {
                try {
                    // answer
                    final String json = "";

                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {

                            adapter = new ViewPagerItemAdapter(ViewPagerItems.with(MainActivity.this)
                                    .add("tab1", R.layout.fragment_tab1)
                                    .add("tab2", R.layout.fragment_tab2)
                                    .add("tab3", R.layout.fragment_tab3)
                                    .create());

                            ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
                            viewPager.setAdapter(adapter);

                            SmartTabLayout viewPagerTab = (SmartTabLayout) findViewById(R.id.viewpagertab);
                            viewPagerTab.setViewPager(viewPager);

                            // after answer
                            TextView textView1 = (TextView) adapter.getPage(0).findViewById(R.id.textView1);
                            textView1.setText("1 - ok");
                            TextView textView2 = (TextView) adapter.getPage(1).findViewById(R.id.textView2);
                            textView2.setText("2 - ok");
                            TextView textView3 = (TextView) adapter.getPage(2).findViewById(R.id.textView3);
                            textView3.setText("3 - ok");

                        }
                    });
                } catch (Exception e) {
                    //runOnUiThread(checkInternetConnection);
                    e.printStackTrace();
                }
            }
        };
        thread.start();
    }
}

but the error still exists

I'm sorry, I did not understand how to use instantiateItem

from smarttablayout.

ogaclejapan avatar ogaclejapan commented on August 29, 2024

Page(Fragment/View) is generated at the same time as the drawing of view.
instantiateItem is called from ViewPager when the necessary generation of Page(Fragment/View).

So, it should pass as an argument of Fragment To resolve this problem without too much change your implementation.

//...

adapter = getSupportFragmentManager(), FragmentPagerItems.with(this)
        .add("tab1", fragment_tab_a.getClass(), new Bundler().putString("result", "1-ok").get())
//...

from smarttablayout.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.