I am trying to add tabbed views to an app I am working on which incorporates an sqlite db.
I want to populate the FragmentPagerAdapter using one of my DAO objects however I have not been able to adapt the array examples I have found on the stackoverflow, tutorial and gits.
Below is my last attempt on the adapter. Any suggestions/advice would be greatly appreciated.
enter code here
package com.netunleashed.independenttestingservices.activities;
import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.util.Log;
import com.netunleashed.independenttestingservices.R;
import com.netunleashed.independenttestingservices.dao.TestSitesDAO;
import com.netunleashed.independenttestingservices.model.TestSite;
import java.util.List;
/**
* Created by jbmacbook on 7/01/16.
*/
public class DevicePagerAdapter extends FragmentPagerAdapter{
private TestSitesDAO mTestSitesDao;
public static final String TAG = "DevicePagerAdapter";
List<TestSite> listTestSites = mTestSitesDao.getAllTestSites();
int listCount = listTestSites.size();
String[] deviceDescription;
public DevicePagerAdapter(FragmentManager fm, Context context) {
super(fm);
Resources resources= context.getResources();
deviceDescription = resources.getStringArray(R.array.deviceDescription);
Log.d(TAG,"DevicePagerAdapter constructed");
}
/**
* Return the Fragment associated with a specified position.
*
* @param position
*/
@Override
public Fragment getItem(int position) {
Log.d(TAG,"getItem started");
Bundle bundle = new Bundle();
bundle.putString(DeviceFragment.DescriptionKey,listTestSites.get(position).getIdentifier());
DeviceFragment deviceFragment = new DeviceFragment();
deviceFragment.setArguments(bundle);
return deviceFragment;
}
@Override
public CharSequence getPageTitle(int position) {
return listTestSites.get(position).getIdentifier();
}
/**
* Return the number of views available.
*/
@Override
public int getCount() {
int listCount = listTestSites.size();
return listCount;
}
}
Aucun commentaire:
Enregistrer un commentaire