如何通过数据传递来制作列表视图图像和文本片段

时间:2018-09-08 02:40:08

标签: android listview fragment

请帮助我解决这个问题,在旧代码中将数据显示为轮播,现在必须将显示更改为列表视图,所有数据已从另一个片段传递,在轮播视图中工作正常,之后我更改为列表视图它不起作用,我该怎么办?

这是从另一个片段传来的数据

public class ListviewPagerAdapter extends FragmentPagerAdapter

private ArrayList<HashMap<String, BluetoothGattService>> mCurrentServiceData;

public ListviewPagerAdapter (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;

}
@Override
public Fragment getItem(int position) {
position = mCurrentServiceData.size();
    HashMap<String, BluetoothGattService> item = 
    mCurrentServiceData.get(position);
    BluetoothGattService bgs = item.get("UUID");
int imageId = GattAttributes.lookupImage(bgs.getUuid());
    String name = GattAttributes.lookupUUID(bgs.getUuid(),
            mContext.getResources().getString(
                    R.string.profile_control_unknown_service));
    UUID uuid = bgs.getUuid();
    if (uuid.equals(UUIDDatabase.UUID_IMMEDIATE_ALERT_SERVICE)) {
        name = mContext.getResources().getString(R.string.findme_fragment);
    }
    if (uuid.equals(UUIDDatabase.UUID_LINK_LOSS_SERVICE)
            || uuid.equals(UUIDDatabase.UUID_TRANSMISSION_POWER_SERVICE)) {
        name = mContext.getResources().getString(R.string.proximity_fragment);
    }
Fragment curFragment = ListViewFragment.newInstance(imageId,name, uuid.toString(), bgs);
    return curFragment;
}

这是要显示的片段

public class ListViewFragmentextends Fragment {
public static Fragment newInstance(int pos,String name, String uuid, BluetoothGattService service) {
    ListViewFragmentmFragment = new ListViewFragment();

    uuid = uuid + service.getInstanceId();

    mBleHashMap.put(uuid, service);
    Bundle mBundle = new Bundle();
    mBundle.putInt(EXTRA_FRAG_POS, pos);
    mBundle.putString(EXTRA_FRAG_NAME, name);
    mBundle.putString(EXTRA_FRAG_UUID, uuid);
    mFragment.setArguments(mBundle);
    return mFragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(
            R.layout.carousel_fragment_item, container, false);

    final int pos = this.getArguments().getInt(EXTRA_FRAG_POS);
    final String mName = this.getArguments().getString(EXTRA_FRAG_NAME);
    final String mUuid = this.getArguments().getString(EXTRA_FRAG_UUID);

    TextView mTv = (TextView) rootView.findViewById(R.id.text);
    mTv.setText(mName);

    if (mName.equalsIgnoreCase(getResources().getString(
            R.string.profile_control_unknown_service))) {
        mService = mBleHashMap.get(mUuid);
        mCurrentUUID = mService.getUuid();

        UUID UUID_TEMPERATURE_SERVICE = UUID.fromString(TEMPERATURE_SERVICE);

    if (mCurrentUUID==UUID_TEMPERATURE_SERVICE)
    {
        mTv.setText("Temperature service");
    }
        TextView mTvUUID = (TextView) rootView.findViewById(R.id.text_uuid);
        mTvUUID.setText(mCurrentUUID.toString());
    }

0 个答案:

没有答案