【发布时间】:2016-03-16 08:47:24
【问题描述】:
当我在 android 中使用 layoutInflater 在列表中创建自定义布局时,然后在 LayoutInflater 的声明中给出错误无法访问的声明。如何解决它
public View getView(int position, View convertView, ViewGroup parent) {
return super.getView(position, convertView, parent);
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View vw = inflater.inflate(R.layout.list_custom , parent,false);
Tour tour = tours.get(position);
TextView tv =(TextView) vw.findViewById(R.id.texttile);
tv.setText(tour.getTitle());
tv =(TextView) vw.findViewById(R.id.price);
NumberFormat nf= NumberFormat.getCurrencyInstance();
tv.setText(nf.format(tour.getPrice()));
ImageView iv =(ImageView) vw.findViewById(R.id.imageview);
int imageResource = context.getResources().getIdentifier(tour.getImage() , "drawable" , context.getPackageName());
if (imageResource!=0){
iv.setImageResource(imageResource);
}
return vw;
}
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 说无法到达的声明
【问题讨论】:
-
你看到
return声明了吗? -
这正是警告所说的内容。
-
它将执行返回行并退出该方法。只需将代码放在 return 语句之前。
-
这是编程的基础知识:
Every method should have only a single exit point
标签: android