The question is not as complex as it seems.
I made this design based on some tutorials on the internet.
I have a tabbed browsing with swipe using SupportLibrary for devices prior to Honeycomb can visualize.
Now I want to add a ActionBar in the application. Also by using the SuportLibrary appcompat.v7.
I've used the appcompat.v7 to create an application with ActionBar compatible with older versions of Android.
What I'm not getting now and join these two navigational structures.
I really want to add to this mu ActionBar project with swipe tabs below:
MainActivity:
package br.com.wgbn.poemadodiav2;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.view.Menu;
public class MainActivity extends FragmentActivity {
private ActionBar actionBar;
private ViewPager mViewPager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mViewPager = (ViewPager) findViewById(R.id.viewpager);
TitleAdapter titleAdapter = new TitleAdapter(getSupportFragmentManager());
mViewPager.setAdapter(titleAdapter);
mViewPager.setCurrentItem(0);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
TitleAdapter:
package br.com.wgbn.poemadodiav2;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.util.Log;
public class TitleAdapter extends FragmentPagerAdapter{
private String titles[] = new String[]{"O Poema do Dia","Comentários"};
private Fragment frags[] = new Fragment[titles.length];
public TitleAdapter(FragmentManager fm) {
super(fm);
frags[0] = new FragmentView1();
frags[1] = new FragmentView2();
}
#Override
public CharSequence getPageTitle (int position){
Log.v("TitleAdapter - getPageTitle=", titles[position]);
return titles[position];
}
#Override
public Fragment getItem(int position) {
Log.v("TitleAdapter - getItem=", String.valueOf(position));
return frags[position];
}
#Override
public int getCount() {
return frags.length;
}
}
activity_main.xml:
<LinearLayout 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:orientation="vertical"
tools:context=".MainActivity" >
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
<android.support.v4.view.PagerTabStrip
android:id="#+id/pagerTabStrip"
android:layout_gravity="bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#cccccc"/>
</android.support.v4.view.ViewPager>
</LinearLayout>
This is the image of the app working so far.
I hope you can help me.
EDIT
Following the guidance of NikolaDespotoski, decided the issue only changing the extension class for ActionBarActivity!
Actually I was thinking it had to implement the two things together, without realizing that ActionBarActivity already encompassed both.
My code looked like this, and it worked:
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
public class MainActivity extends ActionBarActivity {
// code here
}
Thanks!
Related
I have researched a lot on SharedElement Transitions , however I could only find Transitions for onclick event.
I want the animation between Fragments where the speed of animation is controlled by the user's scrolling speed. If the user stops in between while scrolling the objects should be still.
Example :
In this image , the viewpager is in the middle of screen1 and screen2 and the animating objects are in stopped state.
These objects move from one screen to another and also change their positions.
The translation animations part I have figured out but how to achieve this shared element transition with viewpager between fragments. And moreover it should scroll/animate with the speed of finger swipe.
MainActivity.java
package com.karan.onboardanimation;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
private MyFragmentPagerAdapter pagerAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(TAG, "onCreate: ");
ViewPager pager = (ViewPager) findViewById(R.id.pager);
FragmentManager fm = getSupportFragmentManager();
pagerAdapter = new MyFragmentPagerAdapter(fm);
pager.setAdapter(pagerAdapter);
pager.setCurrentItem(0);
}
}
FirstFragment.java- This fragment has an imageview which has to shared with second fragment when user is swiping on the viewpager.
package com.karan.onboardanimation;
import android.app.ActivityOptions;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
public class FirstFragment extends Fragment {
private static final String TAG = "FirstFragment";
ImageView imageView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= 21){
}
Log.d(TAG, "onCreate: ");
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.d(TAG, "onCreateView: ");
View view = inflater.inflate(R.layout.first_fragment, container, false);
imageView = (ImageView) view.findViewById(R.id.img1);
ViewPagerTransformer viewPagerTransformer = new ViewPagerTransformer();
viewPagerTransformer.transformPage(imageView, 1);
return view;
}
}
MyFragmentPagerAdapter.java
package com.karan.onboardanimation;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.util.Log;
class MyFragmentPagerAdapter extends FragmentPagerAdapter {
private static final String TAG = "MyFragmentPagerAdapter";
final int PAGE_COUNT = 2;
public MyFragmentPagerAdapter(FragmentManager fm) {
super(fm);
Log.d(TAG, "MyFragmentPagerAdapter: ");
}
#Override
public Fragment getItem(int position) {
Log.d(TAG, "getItem: ");
switch (position) {
case 0:
return new FirstFragment();
case 1:
return new SecondFragment();
default:
return null;
}
}
#Override
public int getCount() {
return PAGE_COUNT;
}
}
second_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#d02030"
android:orientation="vertical">
<ImageView
android:id="#+id/img2"
android:layout_width="100dp"
android:layout_centerInParent="true"
android:src="#drawable/orange_centre"
android:transitionName="selectedIcon"
android:layout_height="100dp" />
</RelativeLayout>
first_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/img1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:src="#drawable/orange_centre" />
</LinearLayout>
Edit1-
This question is not a duplicate of link mentioned in comment because that question is a sub part of my question. The difference is that the animation in that question happens on a click with a static speed. However in my question, the speed of animation must be equal to the speed of ViewPager swipe speed.
You can try PageTransformer. It is not shared transition but more of view animation that is dependent on page position offset generated by swipe events.
I am using fragments to get the Tabs style on my app, like seen here:
Tabs
Already deducted that each tab is a fragment and each one has a layout, but i cant display on each one display what i want.
Before having the fragments i had a simple activity to display data from a database on a listview, but now i cant get it to work on one of the fragments, with the following code that i used:
dal = new DAL(TabListas.this);
dal.connect(DBAccessMode.READ);
Cursor cursor = dal.selectALLFromRegSintomas();
// Find ListView to populate
ListView lvItems = (ListView) findViewById(R.id.listv);
// Setup cursor adapter using cursor from last step
RegistosCursorAdapter todoAdapter = new RegistosCursorAdapter(TabListas.this, cursor, 0);
// Attach cursor adapter to the ListView
lvItems.setAdapter(todoAdapter);
How can i make a use the fragments to display data from db in a listview in one fragment ? What should i change ?
VerRegsSintomas.java (like mainactivity.java):
package com.example.bugdroid.menuexe.Activities;
import android.app.Activity;
import android.database.Cursor;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.widget.ListView;
import com.example.bugdroid.menuexe.CursorAdapter.RegistosCursorAdapter;
import com.example.bugdroid.menuexe.R;
import com.example.bugdroid.menuexe.TabFragments.PageAdapter;
import com.example.bugdroid.menuexe.database.DAL;
import com.example.bugdroid.menuexe.database.DBAccessMode;
public class VerRegsSintomas extends AppCompatActivity {
private ViewPager mViewPager;
private DAL dal;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ver_regs_sintomas);
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#1a212c")));
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
tabLayout.addTab(tabLayout.newTab().setText("Sintomas"));
tabLayout.addTab(tabLayout.newTab().setText("Listas"));
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
final PageAdapter adapter = new PageAdapter
(getSupportFragmentManager(), tabLayout.getTabCount());
viewPager.setAdapter(adapter);
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
#Override
public void onTabSelected(TabLayout.Tab tab) {
}
#Override
public void onTabUnselected(TabLayout.Tab tab) {
}
#Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
}
}
PageAdapter.java:
package com.example.bugdroid.menuexe.TabFragments;
/**
* Created by BugDroid on 07/06/2016.
*/
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
public class PageAdapter extends FragmentStatePagerAdapter {
int mNumOfTabs;
public PageAdapter(FragmentManager fm, int NumOfTabs) {
super(fm);
this.mNumOfTabs = NumOfTabs;
}
#Override
public Fragment getItem(int position) {
switch (position) {
case 0:
TabSintomas tab1 = new TabSintomas();
return tab1;
case 1:
TabListas tab2 = new TabListas();
return tab2;
default:
return null;
}
}
#Override
public int getCount() {
return mNumOfTabs;
}
}
TabSintomas.java:
package com.example.bugdroid.menuexe.TabFragments;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.bugdroid.menuexe.R;
public class TabSintomas extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_tab_sintomas, container, false);
}
}
fragment_Tab_sintomas.xml
<?xml version="1.0" encoding="utf-8"?>
<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/activity_vertical_margin"
tools:context=".Activities.VerRegistos">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/listv"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
Try this Example ,here you can find a TabLayout with the help of Viewpager and custom toolbar and along with this all you can find a navigation drawer over there.
I am trying to implement a simple ListView into a Fragment. I have seen many tutorials on how to do so but for some reason my adaptation does not work and I cannot figure out why.
the goal: to have a fragment with one listview.
I understand there are many questions about this and I have seen most of them but mine does not work and I have tried many variations with no success.
From what I have gathered ListFragment and AppCompatActivity are the most appropiate:
//code for fragment.
package com.example.student.hwapp;
import android.support.v4.app.ListFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
public class TasksFragment extends ListFragment {
public TasksFragment(){}
public String[] list = {"1","2","3","4","5","6"};
ListAdapter theAdapter;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
View rootView = inflater.inflate(R.layout.tasks_fragment,container,false);
theAdapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1, list);
setListAdapter(theAdapter);
return rootView;
}
public static TasksFragment newInstance() {
TasksFragment fragment = new TasksFragment();
return fragment;
}
}
the XML for tasks_fragment (as you can see the list id is list) :
<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">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/list"
tools:listitem="#android:layout/simple_list_item_2"
android:choiceMode="multipleChoice"
android:footerDividersEnabled="false"
android:clickable="false" />
</RelativeLayout>
and finally the Activity that holds the fragment:
package com.example.student.hwapp;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainMenu extends AppCompatActivity {
private SectionsPagerAdapter mSectionsPagerAdapter;
private ViewPager mViewPager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_menu);
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
switch(position){
case 0:
return TasksFragment.newInstance();
case 1:
return ClassFragment.newInstance();
}
return null;
}
#Override
public int getCount() {
// Show 2 total pages.
return 2;
}
#Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return "SECTION 1";
case 1:
return "SECTION 2";
}
return null;
}
}
When I test the TasksFragment as a normal activity, it actually works but when I make it a fragment it doesn't.
Thank you for your help, sorry for the very specific and repetitive question but I really could not find a solution, I'm probably missing something very simple.
EDIT:
14203/com.example.student.hwapp E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
But I DO have a ListView and its id IS list as I showed in the code.
Your android:id="#+id/list" is not the same as what is being asked for in the error message, which is android:id="#android:id/list". The former is YOUR object; Android needs its OWN object. Refer to this, among many others.
I need to use tabs on my app ,
I may need 4 to 7 tabs on my fragmentActivity .
I heard swipe tabs are best suited for displaying 3 or fewer tabs . I've already use them in another app but the number of tabs was 3 . I don't know if it's true or not but they worked perfect on that app .
I need to make something like Google Play Store app , as you can see there are lots of tabs , what are those tabs ?
I don't need to have any communication between these tabs .
What is the best tab to use when I have 4 to 7 tabs ?
I need to run the app on older devices like 2.3+
thanks you
Google Play store app uses Scrolling Tabs. Here's an example:
MainActivity.java
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class MainActivity extends ActionBarActivity {
// used ActionBarActivity from v7 support library,
// for backward compatibility
private ViewPager viewPager;
private MyPagerAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewPager = (ViewPager) findViewById(R.id.viewPager);
adapter = new MyPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(adapter);
}
private static class MyPagerAdapter extends FragmentPagerAdapter {
public MyPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int arg0) {
// each page corresponds to a new fragment
// I'll return the same fragment for now
return new MyFragment();
}
#Override
public int getCount() {
// return no of pages
return 5;
}
#Override
public CharSequence getPageTitle(int position) {
// return the page title
return "Tab " + position;
}
}
public static class MyFragment extends Fragment {
public MyFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
return rootView;
}
}
}
activity_main.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="MergeRootFrame" >
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.view.PagerTitleStrip
android:id="#+id/tabs"
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>
</FrameLayout>
fragment_main.xml is just the hello world fragment. You will need to customize the PagerTitleStrip to make it look like a tab. For that I really love this library.
Hope this helps :)
It is better to use scroll tabs in your case.
Use fragment class from support.v4.app lib,this will enable you to use scroll tabs with devices older than API level 11.
For using support lib,include it in dependencies in builf.gradle file.
Also extend adapter with FragmentStatePagerAdapter instead of FragmentPagerAdapter to store the instance before it getting destroyed.
Here is an example code snippet
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends FragmentActivity {
ViewPager pager = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pager = (ViewPager) findViewById(R.id.pager);
android.support.v4.app.FragmentManager manager = getSupportFragmentManager();
pager.setAdapter(new MyAdapter(manager));
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public class MyAdapter extends FragmentStatePagerAdapter{
public MyAdapter(android.support.v4.app.FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int i) {
Fragment frag = null;
if(i==0){
frag = new FragmentA();
}
if(i==1){
frag = new FragmentB();
}
if(i==2){
frag = new FragmentC();
}
return frag;
}
#Override
public int getCount() {
return 3;
}
public CharSequence getPageTitle(int i){
String title = new String();
if(i==0){
title = "FRAG1";
}
if(i==1){
title = "FRAG2";
}
if(i==2){
title = "FRAG3";
}
return title;
}
}
}
I am having some trouble with this piece of code:
MyAdapter.java:
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
public static class MyAdapter extends FragmentStatePagerAdapter {
public MyAdapter(FragmentManager fm) {
super(fm);
}
#Override
public int getCount() {
return 3;
}
#Override
public Fragment getItem(int position) {
switch (position) {
case 0: return new SpeedZonesFragment();
case 1: return new DistanceFragment();
case 2: return new FuelConsumptionFragment();
default: return null;
}
}
}
MainActivity.java:
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
public class MainActivity extends FragmentActivity {
private MyAdapter myAdapter;
private ViewPager myViewPager;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_pager);
myAdapter = new MyAdapter(getSupportFragmentManager());
myViewPager = (ViewPager) findViewById(R.id.pager);
myViewPager.setAdapter(myAdapter);
view_pager.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/view_pager" />
</LinearLayout>
My problem goes that every example i can find declares MyAdapter as a public static class however Eclipse raise the error: Illegal modifier for the class MyAdapter; only public, abstract & final are permitted.
If i try to run my code without the static it returns (from LogCat):
Caused by: java.lang.NullPointerException
02-02 23:13:26.076: E/AndroidRuntime(928):
at simcas.fartberegneren.MainActivity.onCreate(MainActivity.java:23)
EDIT: Line 23 is the line myViewPager.setAdapter(myAdapter);
Clearly i am doing something wrong but i just can't locate it.
Firstly, no, static classes are only used for inner classes wherein the inner class's instances should not be tied to the outer class's instance. (That is, in an outer class, the static modified should not be used.)
Second, the null pointer is in the statement myViewPager.setAdapter(myAdapter);, as you deduced, meaning myViewPager is null. Therefore, the findViewById() is returning null (item not found):
myViewPager = (ViewPager) findViewById(R.id.pager);
Notice, in your XML: android:id="#+id/view_pager". The above line should then be:
myViewPager = (ViewPager) findViewById(R.id.view_pager);