2015-08-26 34 views
-3

時自定義列表視圖,在方法getView我使用的ImageView我不找佈局ID

img=view.findViewById(); 

我沒有在我的佈局customlistView.My代碼如下找回ID:

public class CustomAdapter extends ArrayAdapter<ItemMenu> { 

    Context context; 
    int resource; 
    List<ItemMenu> objects; 

    public CustomAdapter(Context context, int resource, List<ItemMenu> objects) { 
     super(context, resource, objects); 
     // TODO Auto-generated constructor stub 
     this.context = context; 
     this.resource = resource; 
     this.objects = objects; 

    } 
    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     // TODO Auto-generated method stub 
     View view=View.inflate(context, resource, null); 
     ImageView img=view.findViewById(); 
     return super.getView(position, convertView, parent); 
    } 

} 
+2

您沒有提供'id'參數,看起來像。 –

回答

0

使用此行代碼

ImageView img=(ImageView)view.findViewById(R.id.imageId); 

用layout中的圖像id替換imageId。 `

0

替換這段代碼ImageView img = view.findViewById();與ImageView img =(ImageView)view.findViewById(R.id.imgViewId);

相關問題