I'm using "android.support.v4.view.ViewPager" in my app. And I'm using this code to initializing Tabs.
mCollectionPagerAdapter = new CollectionPagerAdapter(getSupportFragmentManager());
final ActionBar actionBar = getActionBar();
actionBar.setHomeButtonEnabled(false);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mCollectionPagerAdapter);
mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener()
{
@Override
public void onPageSelected(int position)
{
actionBar.setSelectedNavigationItem(position);
}
});
for (int i = 0; i < mCollectionPagerAdapter.getCount(); i++)
{
actionBar.addTab(actionBar.newTab().setText(mCollectionPagerAdapter.getPageTitle(i)).setTabListener(this));
}
In the Tab3 Layout I created listview. Now when I call list view by this coding null pointer exception showing:
ListView songsListView = (ListView)findViewById(R.id.NotificationslistView);
String[] songsArray = new String[10];
for(int i=0; i < songsArray.length; i++)
{
songsArray[i] = "Song " + i;
}
ArrayAdapter arrayAdapter = new ArrayAdapter(view.getContext(), android.R.layout.simple_list_item_1, songsArray);
Note 1: all that codes in the main activity calling after oncreate method. Note 2: I'm using this code to inflate Tab3 layout, and it solve Nullexceptionpointer error, but dosn't show anything in listview !!
View view;
LayoutInflater inflater = (LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.tab3, null);
ListView songsListView = (ListView) view.findViewById(R.id.NotificationslistView);