大于两个的if分支,使用switch
This commit is contained in:
@ -24,16 +24,20 @@ public class NewsUtils {
|
||||
* 根据新闻类型获取标签背景资源
|
||||
*/
|
||||
public static int getDrawableIdByType(String type) {
|
||||
if ("活动".equals(type) || "高阶".equals(type)) {
|
||||
return R.drawable.textview_red_up;
|
||||
} else if ("公告".equals(type) || "中期".equals(type)) {
|
||||
return R.drawable.textview_orange_up;
|
||||
} else if ("新游".equals(type)) {
|
||||
return R.drawable.textview_green_up;
|
||||
} else if ("热门".equals(type) || "置顶".equals(type)) {
|
||||
return R.drawable.textview_all_red_up;
|
||||
} else {
|
||||
return R.drawable.textview_blue_up;
|
||||
switch (type) {
|
||||
case "活动":
|
||||
case "高阶":
|
||||
return R.drawable.textview_red_up;
|
||||
case "公告":
|
||||
case "中期":
|
||||
return R.drawable.textview_orange_up;
|
||||
case "新游":
|
||||
return R.drawable.textview_green_up;
|
||||
case "热门":
|
||||
case "置顶":
|
||||
return R.drawable.textview_all_red_up;
|
||||
default:
|
||||
return R.drawable.textview_blue_up;
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,18 +90,25 @@ public class NewsUtils {
|
||||
}
|
||||
|
||||
textView.setTextColor(Color.WHITE);
|
||||
if ("活动".equals(type)) {
|
||||
textView.setBackgroundResource(R.drawable.textview_orange_style);
|
||||
} else if ("公告".equals(type)) {
|
||||
textView.setBackgroundResource(R.drawable.textview_red_style);
|
||||
} else if ("评测".equals(type)) {
|
||||
textView.setBackgroundResource(R.drawable.textview_red_style);
|
||||
} else if ("杂谈".equals(type)) {
|
||||
textView.setBackgroundResource(R.drawable.textview_orange_style);
|
||||
} else if ("专题".equals(type)) {
|
||||
textView.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
} else {
|
||||
textView.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
switch (type) {
|
||||
case "活动":
|
||||
textView.setBackgroundResource(R.drawable.textview_orange_style);
|
||||
break;
|
||||
case "公告":
|
||||
textView.setBackgroundResource(R.drawable.textview_red_style);
|
||||
break;
|
||||
case "评测":
|
||||
textView.setBackgroundResource(R.drawable.textview_red_style);
|
||||
break;
|
||||
case "杂谈":
|
||||
textView.setBackgroundResource(R.drawable.textview_orange_style);
|
||||
break;
|
||||
case "专题":
|
||||
textView.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
break;
|
||||
default:
|
||||
textView.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user