如何在片段Android中将哈希图声明到列表视图中?

时间:2018-08-26 15:16:36

标签: android listview bluetooth android-viewpager

在数据显示使用Carousel视图之前,我已经尝试了很多次,但是总是失败,但是我想更改为listview视图,如何进行更改?

ProfileControlFragment

public class ProfileControlFragment extends Fragment {
....
public ProfileControlFragment create(String device_name,
                                          String device_address) {
        ProfileControlFragment fragment = new ProfileControlFragment();
        Bundle args = new Bundle();
        args.putString(ARG_DEVICE_NAME, device_name);
        args.putString(ARG_DEVICE_ADDRESS, device_address);
        fragment.setArguments(args);
        return fragment;
    }
 private void setCarouselView() {

        // Getting the number of services discovered
        mPages = ServiceDiscoveryFragment.mGattServiceData.size();
        FIRST_PAGE = mPages * LOOPS / 2;

        // Setting the adapter
        mAdapter = new CarouselPagerAdapter(getActivity(),
                ProfileControlFragment.this, getActivity()
                .getSupportFragmentManager(),
                ServiceDiscoveryFragment.mGattServiceData);
        mPager.setAdapter(mAdapter);
        mPager.setOnPageChangeListener(mAdapter);
        // Set current item to the middle page so we can fling to both
        // directions left and right
        mPager.setCurrentItem(FIRST_PAGE);
        // Necessary or the pager will only have one extra page to show
        // make this at least however many pages you can see
        mPager.setOffscreenPageLimit(3);

        if (mPages == 0) {
            Toast.makeText(getActivity(), getResources().getString(R.string.toast_no_services_found), Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(getActivity(), getResources().getString(R.string.toast_swipe_profiles), Toast.LENGTH_SHORT).show();
        }
    }

适配器

public class CarouselPagerAdapter extends FragmentPagerAdapter
...
public CarouselPagerAdapter(Activity context,
                            ProfileControlFragment containerFragment,
                            FragmentManager fragmentManager,
                            ArrayList<HashMap<String, BluetoothGattService>> currentServiceData) {
    super(fragmentManager);
    this.mFragmentManager = fragmentManager;
    this.mContext = (HomePageActivity) context;
    this.mContainerFragment = containerFragment;
    this.mCurrentServiceData = currentServiceData;

}

0 个答案:

没有答案