Android app with fragment in lollipop version not working done but works in another version

159 Views Asked by At

I previously changed API from 21 to 26, then changed Android version 4 to version 7. When running the application on Android Lollipop I did not get an error but the application did not run properly. Strangely, it run well at another Android Version.

when clicking the button (button bPayment, for example), the views should change, but in lolipop it can't change. When it clicked, the action runs except the views won't change. So it looks like the previous screen / data piles and just stacked up on the front. What make it a bit confusing is, i still can access the views that placed under current views. Whereas in another android version, the current views just gone away after button is clicked.

So, in simplest words, the snippet code below run perfectly at any android version except Lolipop. How to get it works on android Lolipop ? Any help or hint will be much appreciated.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    /**
     * Inflate the layout for this fragment
     */

    final View view = inflater.inflate(R.layout.favourite_layout, container, false);

    context = getActivity();
    activity = getActivity();
    app = (MobileBankingApplication) context.getApplicationContext();

    list = (ListView) view.findViewById(R.id.favourite_exchange_list);
    list.addFooterView(new View(context), null, true);
    list.setSmoothScrollbarEnabled(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD)
        list.setOverScrollMode(View.OVER_SCROLL_ALWAYS);

    list.setVisibility(View.VISIBLE);
    list.startLayoutAnimation();
    getFavouritePaymentHandler();

    ImageView imageSeparator = (ImageView) getActivity().findViewById(R.id.imageViewSeparator);
    Button buttonBack = (Button) getActivity().findViewById(R.id.button_back);
    TextView title = (TextView) getActivity().findViewById(R.id.actionbar_title);
    title.setText(getResources().getString(R.string.favourite).toUpperCase());
    ImageView imageProfile = (ImageView) getActivity().findViewById(R.id.image_home);
    imageProfile.setVisibility(View.INVISIBLE);
    imageSeparator.setVisibility(View.INVISIBLE);
    buttonBack.setVisibility(View.INVISIBLE);

    tableRecurring = (TableLayout) view.findViewById(R.id.tableRecurring);
    tableHeader = (TableLayout) view.findViewById(R.id.tableHeader);
    layoutHeader = (LinearLayout) view.findViewById(R.id.layoutHeader);
    layoutRecurring = (RelativeLayout) view.findViewById(R.id.layoutRecurring);

    bPayment = (Button) view.findViewById(R.id.button1);
    bPayment.setBackgroundResource(R.drawable.tab_favourite_selected);
    bPayment.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            bRecurring.setBackgroundResource(R.drawable.tab_favourite);
            bPayment.setBackgroundResource(R.drawable.tab_favourite_selected);
            bTransfer.setBackgroundResource(R.drawable.tab_favourite);
            bTopup.setBackgroundResource(R.drawable.tab_favourite);
            layoutRecurring.setVisibility(View.GONE);
            list.setVisibility(View.VISIBLE);
            getFavouritePaymentHandler();
        }
    });

    bTransfer = (Button) view.findViewById(R.id.button2);
    bTransfer.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP || Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP_MR1) {
                Log.d("Transfer 1", "onClick: "+Build.VERSION.SDK_INT);
            } else {
                Log.d("Transfer 2", "onClick: "+Build.VERSION.SDK_INT);
            }

            bRecurring.setBackgroundResource(R.drawable.tab_favourite);
            bPayment.setBackgroundResource(R.drawable.tab_favourite);
            bTransfer.setBackgroundResource(R.drawable.tab_favourite_selected);
            bTopup.setBackgroundResource(R.drawable.tab_favourite);
            layoutRecurring.setVisibility(View.GONE);
            list.setVisibility(View.VISIBLE);
            getFavouriteTransferHandler();
        }
    });

    bTopup = (Button) view.findViewById(R.id.button3);
    bTopup.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            bRecurring.setBackgroundResource(R.drawable.tab_favourite);
            bPayment.setBackgroundResource(R.drawable.tab_favourite);
            bTransfer.setBackgroundResource(R.drawable.tab_favourite);
            bTopup.setBackgroundResource(R.drawable.tab_favourite_selected);
            layoutRecurring.setVisibility(View.GONE);
            list.setVisibility(View.VISIBLE);
            getFavouriteTopUpHandler();

        }
    });

    bRecurring = (Button) view.findViewById(R.id.button4);
    bRecurring.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            bRecurring.setBackgroundResource(R.drawable.tab_favourite_selected);
            bPayment.setBackgroundResource(R.drawable.tab_favourite);
            bTransfer.setBackgroundResource(R.drawable.tab_favourite);
            bTopup.setBackgroundResource(R.drawable.tab_favourite);
            layoutRecurring.setVisibility(View.VISIBLE);
            list.setVisibility(View.GONE);
            getFavouriteRecurringhandler();
        }
    });

    return view;

}
0

There are 0 best solutions below