GridView在每个单元格中包含一组数据

时间:2012-12-24 08:50:32

标签: android gridview android-adapter

我有一个GridView给学生,并认为我用一个学生名称填写每个单元格,并且在每个GridCell该学生的名字中,他也获得了他在一年中获得的所有分数。相同的细胞。所以在每个细胞中我都喜欢:

gridview

  -------------------------------
 |   student 1    |   student 2  |
 |                |              |
 |   a listview   |              |
 | or scrollview  |  a listview  |
 |    ----------  |  ----------- |
 |    english A   |   english B  |
 |    math    A   |   math    A  |
 |    history A   |   history E  |
    -----------------------------

和此

的当前xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/senaryolar_grid"
    android:layout_width="166dp"
    android:layout_height="210dp"
    android:padding="3dp"
    android:background="@color/white">
    <RelativeLayout 
        android:layout_width="166dp"
        android:layout_height="32dp"
        android:background="@drawable/senaryobaslik"
        android:id="@+id/senaryo_baslik">
        <TextView android:layout_width="100dp" 
            android:layout_height="wrap_content" 
            android:id="@+id/senaryo_baslik_tv"
            android:textColor="@color/white"
            android:layout_marginLeft="4dp"
            android:textStyle="bold" />
        <ImageView 
            android:id="@+id/senaryo_baslik_iv" 
            android:src="@drawable/arti" 
            android:layout_width="22dp"
            android:layout_height="18dp"
            android:layout_toRightOf="@id/senaryo_baslik_tv"/>
    </RelativeLayout>
    <ScrollView 
        android:layout_height="50dp"
        android:layout_width="fill_parent"
        android:id="@+id/senaryo_scrollview"
        android:layout_below="@id/senaryo_baslik">
        <LinearLayout android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:id="@+id/senaryo_scroll_ll">
        </LinearLayout>
        </ScrollView>
</RelativeLayout>

所以我的问题是我尝试在我listviews的{​​{1}}函数中生成这些scrollviewgetView()(尝试过两者),因为我不知道{{1}在gridview函数生成getView()时,函数调用了一次,因此我尝试将我的生成器放在gridview函数中,但它没有工作,我得到getview()我的问题是:“我应该在哪里打电话给我getView()?”如果我不能在outofmemoryexception中调用它,请根据学生ID在listview adapter内动态创建它?

我当前的gridview: (我只是把这个getview()的{​​{1}}函数和上面的xml代码展示给我尝试做的事情,但请注意这不是我正在尝试做的事情的正确方法)

gridviewadapter

因此,如果您有一个网格视图适配器,并且您希望在每个网格单元格中创建一个gridviewadapter,而您无法在getview()函数中调用那些public View getView(int position, View grid, ViewGroup parent) { if(grid == null){ grid=layoutInflator.inflate(R.layout.senaryolar_grid, null); } ArrayList<ControlItem> senario_devices = new ArrayList<ControlItem>(); // here think like senario_id is student_id int senario_id = samples_senario.get(position).getSenarioId(); // here think like getSenarioDevices is getStudentMarks senario_devices = dbhelpit.getSenarioDevices(senario_id); int senario_device_size = senario_devices.size(); TextView tv_senario; ImageView iv_senario; // I tried scrollview too since I thought listview adapters created outof memory exception but off course didnt work since its not the main problem ScrollView lv_senario; tv_senario = (TextView) grid.findViewById(R.id.senaryo_baslik_tv); iv_senario = (ImageView) grid.findViewById(R.id.senaryo_baslik_iv); lv_senario = (ScrollView) grid.findViewById(R.id.senaryo_scrollview); tv_senario.setText(samples_senario.get(position).getSenarioName()); int i = 0; LinearLayout ll = (LinearLayout) grid.findViewById(R.id.senaryo_scroll_ll); while(i < senario_device_size){ View temp = layoutInflator.inflate(R.layout.senaryolar_listview, null); TextView tv; ImageView iv; RelativeLayout rl; iv = (ImageView) temp.findViewById(R.id.senaryo_list_baslik_iv); rl = (RelativeLayout) temp.findViewById(R.id.senaryolar_list); tv = (TextView) temp.findViewById(R.id.senaryo_list_text_tv); tv.setText(senario_devices.get(position).getDeviceName()); ll.addView(rl); i++; } return grid; } ,它不一定是listViewAdapter,它只能像listViewAdapters那样回应结果,我希望这个问题很清楚。谢谢!

0 个答案:

没有答案