在这种情况下,我试图返回其他变量的值:
If {{Click text}} of a clicked element is available return clicktext
If {{Clicktext}} is undefined return {{Click ID}}
If {{Clicktext}} and {{Click ID}} are undefined return {{Click Class}}
我已经尝试过了,但是它总是给我错误
function () {
if {{Click Text}} == undefined {
return {{Click ID}};
}
if else ({{Click Text}} === undefined || {{Click ID}} == undefined ) {
return {{Click Classes}};
}
}
答案 0 :(得分:0)
尝试以下操作:
public class CardsViewPager extends PagerAdapter {
Context context;
List<Card> cardList;
LayoutInflater layoutInflater;
public CardsViewPager(Context context, List<Card> cards) {
this.context = context;
this.cardList = cards;
layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return cardList.size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((ScrollView) object);
}
@Override
public Object instantiateItem(ViewGroup container, final int position) {
View itemView = layoutInflater.inflate(R.layout.item_card, container, false);
TextView mTitle = itemView.findViewById(R.id.item_card_title);
mTitle.setText(cardList.get(position).getTitle());
TextView mDescription = itemView.findViewById(R.id.item_card_description);
mDescription.setText(cardList.get(position).getDescription());
ImageView imageView = itemView.findViewById(R.id.item_card_image);
Glide.with(context).load(cardList.get(position).getImage()).into(imageView);
container.addView(itemView);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, "you clicked image " + (position + 1), Toast.LENGTH_LONG).show();
}
});
return itemView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((LinearLayout) object);
}
您要测试的语句应封装在括号中。您发布的if语句不是这种情况。其次,如果else不是有效的条件语句。