Null Pointer Exception In Getview() Of Custom Adapter
I am using this Custom Adapter for my ListView: public class SideMenuAdapter extends BaseAdapter { private static final int TYPE_MAX_COUNT = 2; private static LayoutInflat
Solution 1:
You should initialize vi
before your vi.setTag(holder);
Solution 2:
Try this, might help u...
public View getView(int position, @Nullable View convertView, ViewGroup parent) {
ViewHolderholder=newViewHolder();
Viewvi= convertView;
if (vi == null) {
LayoutInflaterinflater= ((Activity)activity).getLayoutInflater();
vi = inflater.inflate(R.layout.side_menu_list_item, null);
holder.mainText = (TextView) vi.findViewById(R.id.mainText_sideMenu);
holder.sideText = (TextView) vi.findViewById(R.id.sideText_sideMenu);
vi.setTag(holder);
} else {
holder = (ViewHolder) vi.getTag();
}
holder.mainText.setText(values[position]);
if(position == 2){
holder.sideText.setText("3");
holder.sideText.setBackgroundResource(R.drawable.orange);
}
return convertView;
}
Post a Comment for "Null Pointer Exception In Getview() Of Custom Adapter"