-6

When I use layoutInflater in android to create custom layout in list then at the declaration of LayoutInflater give an error unreachable statement . How fix it

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); says unreachble statement

Shree Krishna
  • 8,474
  • 6
  • 40
  • 68
Vp Singh
  • 15
  • 1
  • 4

3 Answers3

2

Problem for your

  return super.getView(position, convertView, parent);

Remove this return.

Actually wrong return statement creates un-reachable statement.

We don't put return statement above any other statement unless that return is under any conditional statement.

Courtesy goes to

I get the error "Unreachable statement" return in android

Community
  • 1
  • 1
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
0

remove line
return super.getView(position, convertView, parent);

sanket
  • 77
  • 2
  • You have [Comment Everywhere](http://stackoverflow.com/help/privileges/comment) privilege. Why are you adding everything as answer ? – Shree Krishna Mar 16 '16 at 08:51
0
   return super.getView(position, convertView, parent);

*REMOVE return keyword after removing

super.getView(position, convertView, parent);
  • Thanks for helping at StackOverflow. The answer is basically correct and constructive, but needs some rephrasing for clarity and readability. – Yunnosch May 11 '17 at 06:08