Buttons inside a tab and swipe view fragment

Kasl

New Member
I'm trying to use a tab and swipe view with fragments to display some data (for now it's just dummy data) for different sections which one can swipe between. To get an idea of what i mean, take a look at the google app store's display for apps as it's roughly how I want to show things to the user.Currently, my program will display the 4 sections that I have listed, but I can't figure out how to show the data that is in each of the sections. (Kind of like if you were looking at the app store and saw the titles for each section, such as "top paid" but not seeing any apps displayed). I've only been programming for a short time so I don't know how a lot of things work for android so giving snippets of example codes would be easier for me to follow than just vague answers of how i should go about it.edit: note, the original code had the program show a page number in the very center of the screen for each section, however I do not need that, but not sure what to do with it.Here is my code for my .java file:\[code\]import android.annotation.SuppressLint;import android.os.Bundle;import android.support.v4.app.Fragment;import android.support.v4.app.FragmentActivity;import android.support.v4.app.FragmentManager;import android.support.v4.app.FragmentPagerAdapter;import android.support.v4.app.NavUtils;import android.support.v4.view.ViewPager;import android.view.Gravity;import android.view.LayoutInflater;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.view.ViewGroup;import android.widget.TextView;public class TurbineExample extends FragmentActivity {/** * The {@link android.support.v4.view.PagerAdapter} that will provide * fragments for each of the sections. We use a * {@link android.support.v4.app.FragmentPagerAdapter} derivative, which * will keep every loaded fragment in memory. If this becomes too memory * intensive, it may be best to switch to a * {@link android.support.v4.app.FragmentStatePagerAdapter}. */SectionsPagerAdapter mSectionsPagerAdapter;/** * The {@link ViewPager} that will host the section contents. */ViewPager mViewPager;@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_turbine_example); // Show the Up button in the action bar. getActionBar().setDisplayHomeAsUpEnabled(true); // Create the adapter that will return a fragment for each of the three // primary sections of the app. mSectionsPagerAdapter = new SectionsPagerAdapter( getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_turbine_example, menu); return true;}@Overridepublic boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: // This ID represents the Home or Up button. In the case of this // activity, the Up button is shown. Use NavUtils to allow users // to navigate up one level in the application structure. For // more details, see the Navigation pattern on Android Design: // // http://developer.android.com/design/patterns/navigation.html#up-vs-back // NavUtils.navigateUpFromSameTask(this); return true; } return super.onOptionsItemSelected(item);}/** * A {@link FragmentPagerAdapter} that returns a fragment corresponding to * one of the sections/tabs/pages. */public class SectionsPagerAdapter extends FragmentPagerAdapter { public SectionsPagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int position) { // getItem is called to instantiate the fragment for the given page. // Return a DummySectionFragment (defined as a static inner class // below) with the page number as its lone argument. Fragment fragment = new DummySectionFragment(); Bundle args = new Bundle(); args.putInt(DummySectionFragment.ARG_PART, position + 1); fragment.setArguments(args); return fragment; } @Override public int getCount() { // Show 4 total pages. return 4; } @Override @SuppressLint("DefaultLocale") public CharSequence getPageTitle(int position) { switch (position) { case 0: return getString(R.string.title_section1).toUpperCase(); case 1: return getString(R.string.title_section2).toUpperCase(); case 2: return getString(R.string.title_section3).toUpperCase(); case 3: return getString(R.string.title_section4).toUpperCase(); } return null; }}/** * A dummy fragment representing a section of the app, but that simply * displays dummy text. */public static class DummySectionFragment extends Fragment { /** * The fragment argument representing the section number for this * fragment. */ public static final String ARG_PART = "section_part"; public DummySectionFragment() { } public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState, int position) { // Create a new TextView and set its text to the fragment's section // number argument value. TextView textView = new TextView(getActivity()); textView.setGravity(Gravity.CENTER); //textView.setText(Integer.toString(getArguments().getInt(ARG_PART))); switch (position) { case 0: //insert data/button to data here return textView; case 1: //insert data/button to data here return textView; case 2: //insert data/button to data here return textView; case 3: //insert data/button to data here return textView; } return textView; }}}\[/code\]not sure if it's needed, but here's the xml as well:\[code\]<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:id="@+id/pager"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".TurbineExample" ><!--This title strip will display the currently visible page title, as well as the pagetitles for adjacent pages.--><android.support.v4.view.PagerTitleStrip android:id="@+id/pager_title_strip" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="top" android:background="#33b5e5" android:paddingBottom="4dp" android:paddingTop="4dp" android:textColor="#fff" /></android.support.v4.view.ViewPager>\[/code\]I think that I should be able to use case statements to put the data for each section into the corresponding section, but again, I'm just guessing. I can't find many good explanation on how to go about doing this, and maybe i can't even do it the way i was thinking, that's why I'm asking for help here.Thank you for any help ahead of time.
 
Back
Top