Android应用程序疑难解答网格视图不支持

时间:2015-12-09 07:01:09

标签: android gridview

我正在使用网格视图而不是listview开发Android应用程序,它完全在模拟器中运行但不在真实设备中运行。安装此应用程序后,我收到消息“不幸的应用已停止”

这是我创建网格视图适配器的代码

class menu
    {
        int menu_image;
        String menu_title;
        menu(int menu_image,String menu_title)
        {
            this.menu_image=menu_image;
            this.menu_title=menu_title;
        }

    }
    class gridAdapter extends BaseAdapter{
        ArrayList<menu> list;
        Context context;
gridAdapter(Context context)
{
    this.context=context;
    list=new ArrayList<menu>();
    String[] menu_tiltes={"news","Artis","events"};
    int [] menu_images={R.mipmap.ic_launcher_artist,R.mipmap.ic_launcher_artist,R.mipmap.ic_launcher_artist};
    for (int i=0;i<3;i++)
    {
        menu tempmenu=new menu(menu_images[i],menu_tiltes[i]);
        list.add(tempmenu);
    }
}
        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public Object getItem(int i) {
            return i;
        }
        class ViewHolder
        {
             ImageView myMenu_image;
            TextView myMenu_title;
            ViewHolder(View v)
            {
                myMenu_image=(ImageView) v.findViewById(R.id.grid_icon_imageView);
               myMenu_title= (TextView) v.findViewById(R.id.facility_textView);
            }
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            View row=view;
            ViewHolder holder=null;
            if(row==null)
            {
                LayoutInflater inflater= (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                row=inflater.inflate(R.layout.single_box_gridview,viewGroup,false);
                holder=new ViewHolder(row);
                row.setTag(holder);
            }
            else
            {
                holder= (ViewHolder) row.getTag();
            }
            menu temp=list.get(i);
            holder.myMenu_image.setImageResource(temp.menu_image);

            holder.myMenu_title.setText(temp.menu_title);

            return row;
        }
    }

请帮帮我

logcat文件

12-09 13:18:59.127 1981-1981/? I/art: Not late-enabling -Xcheck:jni (already on)
12-09 13:18:59.725 1981-2010/com.codeingene.tabdemo D/OpenGLRenderer: Render dirty regions requested: true
12-09 13:18:59.736 1981-1981/com.codeingene.tabdemo D/Atlas: Validating map...
12-09 13:18:59.936 1981-2010/com.codeingene.tabdemo I/OpenGLRenderer: Initialized EGL, version 1.4
12-09 13:19:00.010 1981-2010/com.codeingene.tabdemo D/OpenGLRenderer: Enabling debug mode 0
12-09 13:19:00.068 1981-2010/com.codeingene.tabdemo W/EGL_emulation: eglSurfaceAttrib not implemented
12-09 13:19:00.068 1981-2010/com.codeingene.tabdemo W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa66ac540, error=EGL_SUCCESS
12-09 13:19:01.075 1981-1981/com.codeingene.tabdemo I/Choreographer: Skipped 54 frames!  The application may be doing too much work on its main thread.

我在这个片段类中使用这个适配器

public class tab1 extends Fragment {

    GridView gridView;

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragmanet1, container, false);
        gridView = (GridView) v.findViewById(R.id.gridView_menu);
        gridView.setAdapter(new gridAdapter(getContext()));
        return v;
    }

1 个答案:

答案 0 :(得分:0)

我解决了这个问题!所以不需要回答我的问题。这是由于我的Android工作室的版本问题和更多细节请联系我。