android studio gridview如何实现

我实现的老是黑屏退出
mainactivity.java

 private LayoutInflater inflater;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main); 

        inflater = LayoutInflater.from(getApplicationContext());                
        GridView dev_listview =(GridView)findViewById(R.id.dev_listview);
        MyAdapter gAdapter = new MyAdapter (this);          
        dev_listview.setAdapter(gAdapter);
        setContentView(R.id.dev_listview);
    }

MyAdapter.java

 public class MyAdapter extends BaseAdapter {
      private LayoutInflater inflater;
    private Context mcontext;
    private Integer[] mThumbnails = {R.drawable.unpress9};
    public MyAdapter( Context c) 
    { 
       mcontext = c;
    } 
     public int getCount() {
            return mThumbnails.length;
     }
     public Object getItem(int position) {
            return null;
        }

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


      @SuppressLint("InflateParams")
    public View getView(int position, View grid, ViewGroup parent) 
      {
          inflater = (LayoutInflater)mcontext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    if(grid != null)
     {
        inflater = LayoutInflater.from(mcontext);
        grid =inflater.inflate(R.layout.item_9,parent);
     }

     return grid;

     }

} 

item_9.xml

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="horizontal">
    <LinearLayout
          android:orientation="horizontal">
        <LinearLayout
            android:orientation="horizontal">
            <TextView
                android:id="@+id/text1"/>
            <ImageView
                android:id="@+id/img3" />
        </LinearLayout>
        <LinearLayout
            android:orientation="horizontal">
            <ImageView
                android:id="@+id/img4" />
            <TextView
                android:id="@+id/text2"/>
            <ProgressBar
                android:id="@+id/bar"  />
            <TextView
                android:id="@+id/text3" />
        </LinearLayout>
        <LinearLayout
            android:orientation="horizontal">
            <ImageView
                android:id="@+id/img" />
            <TextView
                android:id="@+id/text4" />
            <ProgressBar
                android:id="@+id/br" />
            <TextView
                android:id="@+id/text5"/>
        </LinearLayout>
                <LinearLayout
            android:orientation="horizontal">
            <ImageView
                android:id="@+id/img94"/>
            <TextView
                android:id="@+id/text6"/>
            <ProgressBar
                android:id="@+id/r" />
            <TextView
                android:id="@+id/text7"/>
        </LinearLayout>
        <LinearLayout
            android:orientation="horizontal">
            <ImageView
                android:id="@+id/img93" />
            <TextView
                android:id="@+id/text8"/>
            <ProgressBar
                android:id="@+id/ar" />
            <TextView
                android:id="@+id/text9"/>
        </LinearLayout>
        <LinearLayout
           android:orientation="horizontal">
            <ImageView
                android:id="@+id/img22" />
            <TextView
                android:id="@+id/text10"/>
            <ProgressBar
                android:id="@+id/ar13" />
            <TextView
                android:id="@+id/text11"/>
        </LinearLayout>
                <LinearLayout
            android:orientation="horizontal">
            <ImageView
                android:id="@+id/img6"/>
            <TextView
                android:id="@+id/text12" />
            <ProgressBar
                android:id="@+id/r17" />
            <TextView
                android:id="@+id/text13"/>
        </LinearLayout>       
         <LinearLayout
            android:orientation="horizontal" >
            <LinearLayout
                android:orientation="vertical" >
                <LinearLayout
                   android:orientation="horizontal" >
                    <TextView
                        android:id="@+id/text17"/>
                    <ImageView
                        android:id="@+id/mg"/>
                    <ImageView
                        android:id="@+id/mg2"/>
                    <ImageView
                        android:id="@+id/dev_ctrl_stat_img3"/>
                    <ImageView
                        android:id="@+id/k"/>
                    <ImageView
                        android:id="@+id/img90"/>
                    <ImageView
                        android:id="@+id/img91"/>
                    <TextView
                        android:id="@+id/text19"/>
                                                <TextView
                        android:id="@+id/text20" />                  
                </LinearLayout>
                <LinearLayout
                    android:gravity="center_vertical" />
                    <ImageView                      
                        android:src="@drawable/img9" />
                    <TextView
                        android:gravity="center_vertical" />
                    <TextView
                        android:layout_width="wrap_content"/>
                </LinearLayout>
            </LinearLayout>
            <LinearLayout
                android:layout_weight="4.5" >
                <ImageView
                    android:id="@+id/qry"/>
            </LinearLayout>

        </LinearLayout>

    </LinearLayout>

</LinearLayout>

想实现的功能是:item.xml全部写进gridview的一个item中,这个item里有9行,我下个item调用令一个5行的item5.xml,要保障不同item每行的高度都一样,如何实现呢,求大神指教!

查看全部
llx2007
凌云志轩
2015/04/16 06:31
  • studio
  • layoutinflater
  • gridview
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

3个回复