erdemgc
erdemgc

Reputation: 1721

Fragments issue

I really need to understand the fragment issue.

What I just wanted to is putting my activity into a fragment or the same functionality into a fragment.

Is it possible?

I have ViewPager and fragments. And I want to display one activity in a fragment in a viewpager.

Upvotes: 2

Views: 102

Answers (1)

Stephane
Stephane

Reputation: 171

I think you take the problem in the wrong way.

  • Fragment are not similar to activities.
  • Fragment is "equivalent" of your view.
  • FragmentActivity display XML with setContentView. This xml will contains one or more Fragment.
  • Each Fragment will be in charge of a part of the UI like ActionBar or anything you want.

So first thing is to create a Fragment wich creates your view. Copy/paste your code relative to this UI (textbox, onclick...) in your new fragment. Then, add your fragment to your main XMl. It will works fine.

Moreover, for viewpager you can find a lot of tutorial on internet, but you have to understand the difference between activities and fragments.

Hope it helps.

Upvotes: 1

Related Questions