@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.data_accessory, container, false); File percentFile = new File( Environment.getExternalStorageDirectory() + "/Android/data/com.jemcphe.xcell/files/settings_accessories"); if (percentFile.exists()) { percentString = FileInfo.readStringFile(getActivity(), "settings_accessories", true); settingsPercent = Double.valueOf(percentString); percent = settingsPercent / 100; } else { FileInfo.storeStringFile(getActivity(), "settings_accessories", "0", true); } ListView listView = (ListView) rootView.findViewById(R.id.listview); TextView accessoryCommissionValue = (TextView) rootView.findViewById(R.id.data_accessoryCommissionValue); TextView accessoryTotalValue = (TextView) rootView.findViewById(R.id.data_accessoryTotalValue); dataSource = new AccessoriesDataSource(getActivity()); dataSource.open(); List<Accessory> accessories = dataSource.findAll(); ArrayList<Double> totals = dataSource.accessoryTotals(); if (accessories.isEmpty()) { String zero = "$0.00"; Log.i("XCELL ACCESSORIES", "EMPTY LIST"); accessoryCommissionValue.setText(zero); accessoryTotalValue.setText(zero); } else { // Loop through totals arraylist for (double i : totals) { accessoryTotal += i; accessoryTotalString = String.format("%.2f", accessoryTotal); } accessoryTotalValue.setText("$" + accessoryTotalString); projectedCommission = accessoryTotal * percent; projectedString = String.format("$%.2f", projectedCommission); accessoryCommissionValue.setText(projectedString); CustomAdapter adapter = new CustomAdapter(getActivity(), R.layout.list_row, accessories); listView.setAdapter(adapter); } return rootView; }
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.frag_mydata); // Create the adapter that will return a fragment for each of the three primary sections // of the app. mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager()); dataSource = new AccessoriesDataSource(this); dataSource.open(); // Set up the action bar. final ActionBar actionBar = getActionBar(); // Up enabled as a workaround for now actionBar.setHomeButtonEnabled(true); // Specify that we will be displaying tabs in the action bar. actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Set up the ViewPager, attaching the adapter and setting up a listener for when the // user swipes between sections. mViewPager = (ViewPager) findViewById(R.id.myDataPager); mViewPager.setAdapter(mAppSectionsPagerAdapter); mViewPager.setOnPageChangeListener( new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { // When swiping between different app sections, select the corresponding tab. // We can also use ActionBar.Tab#select() to do this if we have a reference to the // Tab. actionBar.setSelectedNavigationItem(position); } }); // For each of the sections in the app, add a tab to the action bar. for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) { // Create a tab with text corresponding to the page title defined by the adapter. // Also specify this Activity object, which implements the TabListener interface, as the // listener for when this tab is selected. actionBar.addTab( actionBar .newTab() .setText(mAppSectionsPagerAdapter.getPageTitle(i)) .setTabListener(this)); } }