我以前将API从21更改为26,然后将Android版本4更改为版本7。在Android Lollipop上运行应用程序时,我没有收到错误,但应用程序无法正常运行。奇怪的是,它在另一个Android版本上运行良好。
单击按钮(例如,按钮bPayment)时,视图应该更改,但是在lolipop中,视图不能更改。单击后,该操作将运行,但视图不会更改。因此,它看起来像以前的屏幕/数据堆,只是堆叠在前面。使它有些混乱的是,我仍然可以访问当前视图下的视图。而在另一个Android版本中,单击按钮后,当前视图就消失了。
因此,用最简单的话来说,下面的代码段可以在除Lolipop之外的任何Android版本上完美运行。如何在Android Lolipop上使用它?任何帮助或提示将不胜感激。
@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;
}