请帮帮我 我面对这个问题,我无法解决它,我在我的主要活动(扩展)SherlockFragmentActivity中使用 每个片段扩展了SherlockFragment
package com.Schoolreporting.androidApp.adapter;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.Schoolreporting.androidApp.R;
import com.Schoolreporting.androidApp.model.NavDrawerItem;
public class NavDrawerListAdapter extends BaseAdapter {
private Context context;
private ArrayList<NavDrawerItem> navDrawerItems;
public NavDrawerListAdapter(Context context, ArrayList<NavDrawerItem> navDrawerItems){
this.context = context;
this.navDrawerItems = navDrawerItems;
}
@Override
public int getCount() {
return navDrawerItems.size();
}
@Override
public Object getItem(int position) {
return navDrawerItems.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater)
context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
// here its crash
convertView = mInflater.inflate(R.layout.drawer_list_item, null);
}
ImageView imgIcon = (ImageView) convertView.findViewById(R.id.icon);
TextView txtTitle = (TextView) convertView.findViewById(R.id.title);
TextView txtCount = (TextView) convertView.findViewById(R.id.counter);
imgIcon.setImageResource(navDrawerItems.get(position).getIcon());
txtTitle.setText(navDrawerItems.get(position).getTitle());
// displaying count
// check whether it set visible or not
if(navDrawerItems.get(position).getCounterVisibility()){
txtCount.setText(navDrawerItems.get(position).getCount());
}else{
// hide the counter view
txtCount.setVisibility(View.GONE);
}
return convertView;
}
}
这是我的主要活动
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- Listview to display slider menu -->
<ListView
android:id="@+id/list_slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@color/list_divider"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_selector"
android:background="@color/list_background"/>
</android.support.v4.widget.DrawerLayout>
我的错误日志
07-02 10:57:47.740: E/AndroidRuntime(11411): android.view.InflateException: Binary XML file line #18: Error inflating class <unknown>
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.view.LayoutInflater.createView(LayoutInflater.java:619)
07-02 10:57:47.740: E/AndroidRuntime(11411): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:666)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
07-02 10:57:47.740: E/AndroidRuntime(11411): at com.Schoolreporting.androidApp.adapter.NavDrawerListAdapter.getView(NavDrawerListAdapter.java:48)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.widget.AbsListView.obtainView(AbsListView.java:2603)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.widget.ListView.makeAndAddView(ListView.java:1840)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.widget.ListView.fillSpecific(ListView.java:1327)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.widget.ListView.layoutChildren(ListView.java:1651)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.widget.AbsListView.onLayout(AbsListView.java:2426)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.view.View.layout(View.java:14905)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.view.ViewGroup.layout(ViewGroup.java:4601)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:825)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.view.View.layout(View.java:14905)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.view.ViewGroup.layout(ViewGroup.java:4601)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.view.View.layout(View.java:14905)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.view.ViewGroup.layout(ViewGroup.java:4601)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1694)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1552)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.widget.LinearLayout.onLayout(LinearLayout.java:1465)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.view.View.layout(View.java:14905)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.view.ViewGroup.layout(ViewGroup.java:4601)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.view.View.layout(View.java:14905)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.view.ViewGroup.layout(ViewGroup.java:4601)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2213)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2027)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1237)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5162)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:791)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.view.Choreographer.doCallbacks(Choreographer.java:591)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.view.Choreographer.doFrame(Choreographer.java:561)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:777)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.os.Handler.handleCallback(Handler.java:725)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.os.Handler.dispatchMessage(Handler.java:92)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.os.Looper.loop(Looper.java:176)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.app.ActivityThread.main(ActivityThread.java:5317)
07-02 10:57:47.740: E/AndroidRuntime(11411): at java.lang.reflect.Method.invokeNative(Native Method)
07-02 10:57:47.740: E/AndroidRuntime(11411): at java.lang.reflect.Method.invoke(Method.java:511)
07-02 10:57:47.740: E/AndroidRuntime(11411): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
07-02 10:57:47.740: E/AndroidRuntime(11411): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
07-02 10:57:47.740: E/AndroidRuntime(11411): at dalvik.system.NativeStart.main(Native Method)
07-02 10:57:47.740: E/AndroidRuntime(11411): Caused by: java.lang.reflect.InvocationTargetException
07-02 10:57:47.740: E/AndroidRuntime(11411): at java.lang.reflect.Constructor.constructNative(Native Method)
07-02 10:57:47.740: E/AndroidRuntime(11411): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.view.LayoutInflater.createView(LayoutInflater.java:593)
07-02 10:57:47.740: E/AndroidRuntime(11411): ... 46 more
07-02 10:57:47.740: E/AndroidRuntime(11411): Caused by: android.content.res.Resources$NotFoundException: Resource is not a ColorStateList (color or path): TypedValue{t=0x2/d=0x7f01001f a=3}
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.content.res.Resources.loadColorStateList(Resources.java:2963)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.content.res.TypedArray.getColorStateList(TypedArray.java:343)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.widget.TextView.<init>(TextView.java:903)
07-02 10:57:47.740: E/AndroidRuntime(11411): at android.widget.TextView.<init>(TextView.java:838)
07-02 10:57:47.740: E/AndroidRuntime(11411): ... 49 more
任何建议
答案 0 :(得分:0)
使用
imgIcon.setImageDrawable(convertView.getResources().getDrawable(navDrawerItems.get(position).getIcon()));
而不是
imgIcon.setImageResource(navDrawerItems.get(position).getIcon());