lundi 11 mai 2015

MergeAdapter ClassCastException only w/ Genymotion

I am getting a class cast exception that only occurs when I am using genymotion. Whenever I try this on a real device I do not have an issue.

android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams

at android.widget.ListView.setupChild(ListView.java:1874)

I am using a merge adapter from Commonsware.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    ViewGroup v = (ViewGroup)  inflater.inflate(R.layout.fragment_profile_merge_list, container, false);

    initViews(inflater, container, v);

    setViews();

    setListAdapter(mergeAdapter);

    return v;
}


    public void initViews(LayoutInflater inflater, ViewGroup container, View v) {

    progressBar = (ProgressBar) v.findViewById(R.id.profile_fragment_progress_bar);


    profileHeaderRL = (RelativeLayout) inflater.inflate(R.layout.profile_header_layout, container, false);
    contactInfoRL = (RelativeLayout) inflater.inflate(R.layout.profile_contact_info_layout, container, false);
    addressRL = (RelativeLayout) inflater.inflate(R.layout.profile_address_layout, container, false);
    listingInfoRL = (RelativeLayout) inflater.inflate(R.layout.profile_listing_info_layout, container, false);
    logoutRL = (RelativeLayout) inflater.inflate(R.layout.profile_logout_layout, container, false);

    switch (profileMode) {
        case AGENT_MODE:
            mergeAdapter.addView(profileHeaderRL);
            mergeAdapter.addView(contactInfoRL);
            mergeAdapter.addView(addressRL);
            mergeAdapter.addView(logoutRL);

            break;
        case SEARCH_MODE:
            mergeAdapter.addView(profileHeaderRL);
            mergeAdapter.addView(contactInfoRL);
            mergeAdapter.addView(addressRL);

            break;
        case LISTING_MODE:
            mergeAdapter.addView(profileHeaderRL);
            mergeAdapter.addView(addressRL);
            mergeAdapter.addView(listingInfoRL);
            break;
    }



    profileIV = (RoundedImageView) profileHeaderRL.findViewById(R.id.profile_image_view);
    emailIV = (ImageView) contactInfoRL.findViewById(R.id.profile_email_icon);
    phoneIV = (ImageView) contactInfoRL.findViewById(R.id.profile_phone_icon);
    initialsTV = (TextView) profileHeaderRL.findViewById(R.id.profile_initials_tv);
    nameTV = (TextView) profileHeaderRL.findViewById(R.id.profile_name_tv);
    brokerageTV = (TextView) profileHeaderRL.findViewById(R.id.profile_brokerage_tv);

    officeRL = (RelativeLayout) addressRL.findViewById(R.id.profile_office_rv);

    emailAddressTV = (TextView) contactInfoRL.findViewById(R.id.profile_email_tv);
    phoneNumberTV = (TextView) contactInfoRL.findViewById(R.id.profile_phone_number_tv);
    addressTV = (TextView) addressRL.findViewById(R.id.profile_address_tv);
    cityStateTV = (TextView) addressRL.findViewById(R.id.profile_city_state_tv);
    zipTV = (TextView) addressRL.findViewById(R.id.profile_zip_tv);
    officeTV = (TextView) addressRL.findViewById(R.id.profile_office_tv);
    doneTV = (TextView) profileHeaderRL.findViewById(R.id.profile_done_tv);
    editTV = (TextView) profileHeaderRL.findViewById(R.id.profile_edit_tv);
    logoutButton = (Button) logoutRL.findViewById(R.id.profile_logout_button);

    priceTV = (TextView) listingInfoRL.findViewById(R.id.profile_listing_info_price_tv);
    priceSqftTV = (TextView) listingInfoRL.findViewById(R.id.profile_listing_info_pricesqft_tv);
    bedsTV = (TextView) listingInfoRL.findViewById(R.id.profile_listing_info_beds_tv);
    bathsTV = (TextView) listingInfoRL.findViewById(R.id.profile_listing_info_baths_tv);
    sqftTV = (TextView) listingInfoRL.findViewById(R.id.profile_listing_info_sqft_tv);
    lotSizeTV = (TextView) listingInfoRL.findViewById(R.id.profile_listing_info_lot_size_tv);
    yearTV = (TextView) listingInfoRL.findViewById(R.id.profile_listing_info_years_tv);
    floorsTV = (TextView) listingInfoRL.findViewById(R.id.profile_listing_info_stories_tv);

}

public void setViews() {

    switch (profileMode) {
        case AGENT_MODE:
            setAgentViews();
            setEmailAndPhoneActions();
            break;

        case SEARCH_MODE:
            setSearchViews();
            setEmailAndPhoneActions();
            break;

        case LISTING_MODE:
            setListingViews();
            break;
    }

    nameTV.setText(hsProfileData.getFirstName() + " " + hsProfileData.getLastName());
    initialsTV.setText(ProfileDataFormatter.getInitials(hsProfileData.getFirstName() + " " + hsProfileData.getLastName()));

    HomeStoryApplication.getInstance().getPicasso(getActivity()).
            load(HSApiController.getInstance().getClientProfileImageURL(profileId))
            .fit()
            .centerCrop()
            .into(profileIV, new Callback.EmptyCallback() {
                public void onSuccess() {
                    initialsTV.setVisibility(View.GONE);
                }
            });

    doneTV.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            getActivity().onBackPressed();
        }
    });

    editTV.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switch (profileMode) {
                case AGENT_MODE:
                    Intent editAgentProfileIntent = new Intent(getActivity(), AddNewSearchActivity.class);
                    editAgentProfileIntent.putExtra(PROFILE_ID, profileId);
                    editAgentProfileIntent.putExtra(PROFILE_MODE, AGENT_MODE);
                    startActivity(editAgentProfileIntent);
                    break;
                case SEARCH_MODE:
                    Intent editSearchIntent = new Intent(getActivity(), AddNewSearchActivity.class);
                    editSearchIntent.putExtra(PROFILE_ID, profileId);
                    editSearchIntent.putExtra(PROFILE_MODE, SEARCH_MODE);
                    startActivity(editSearchIntent);
                    break;
                case LISTING_MODE:
                    Intent editListingIntent = new Intent(getActivity(), AddNewListingActivity.class);
                    editListingIntent.putExtra(AddNewListingActivity.EXTRA_PROFILE_ID, listing.getProfileID());
                    startActivity(editListingIntent);
                    break;
            }
        }
    });

}

Aucun commentaire:

Enregistrer un commentaire