Inflateexception On Inflater.inflate() Method Call
I keep getting an InflateException upon trying to inflate a view in my MenuAdapter class. I've surrounded the troublesome code in a try-catch block and get the error Message: link
Solution 1:
When u get Error inflating your class you have to look for the problem in your XML first.
In your case the problem is in your drawer_list_item layout. In your linearLayout root the "?" character causing it with android:background="?android:color/darker_gray" row.
Solution 2:
Use a ViewHolder
http://developer.android.com/training/improving-layouts/smooth-scrolling.html
Change your getView to
public View getView(int position, View convertView, ViewGroup parent){
ViewHolder vh;
if(convertView==null)
{
vh = new ViewHolder();
convertView = inflater.inflate(
R.layout.drawer_list_item, parent, false);
vh.txtTitle = (TextView) convertView.findViewById(R.id.title);
vh.txtSubtitle = (TextView) convertView.findViewById(R.id.subtitle);
vh.imgIcon = (ImageView) convertView.findViewById(R.id.icon);
convertView.setTag(vh);
} else {
vh = (ViewHolder) convertView.getTag();
}
vh.txtTitle.setText(titles[position]);
vh.txtSubtitle.setText(subtitles[position]);
vh.imgIcon.setImageResource(icons[position]);
return convertView;
}
staticclassViewHolder
{
TextView txtTitle,txtSubtitle;
ImageView imgIcon;
}
Also move the below to constructor. Declare this as a class member LayoutInflater inflater
In your constructor
inflater = (LayoutInflater)context.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
Edit:
In drawer_list_item.xml
Change
android:background="?android:color/darker_gray"
to
android:background="@android:color/darker_gray"
Post a Comment for "Inflateexception On Inflater.inflate() Method Call"