Gridview adapter within an adapter

会有一股神秘感。 提交于 2019-12-11 11:13:35

问题


In reference to this question. I have hit a wall, I have both of my adapters set up, and my xml files are nicely lined up. In my activity I have set my content view to the main xml which contains the top gridview. In the adapter I have linked my Imageview to the gridview.

The problem is how do I go about setting the grid_item.xml as my contentview for the inner adapter so that I can link the next image view to the xml?

These are my xml files in order:

main_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <GridView
        android:id="@+id/gridview_main"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_margin="5sp"
        android:columnWidth="60sp"
        android:gravity="center"
        android:horizontalSpacing="10sp"
        android:numColumns="2"
        android:stretchMode="columnWidth"
        android:verticalSpacing="10sp"
        android:clipChildren="true" />

</LinearLayout>

grid_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/category_main_pic"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/arrow_left_dark" />

    <GridView
        android:id="@+id/gridview_item"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_margin="5sp"
        android:columnWidth="90sp"
        android:gravity="center"
        android:horizontalSpacing="10sp"
        android:numColumns="2"
        android:stretchMode="columnWidth"
        android:verticalSpacing="10sp"
        android:clipChildren="true" />
</LinearLayout>

item_grid_image.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/item_main_pic"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/arrow_left_dark" />

</LinearLayout>

I need to get the content of my grid_item.xml for my inner adapter. Any ideas?


回答1:


Ended up settings views (views with images) dependant on the amount of children. Adding a gridview to each gridview element ended up messing up scrolling :).



来源:https://stackoverflow.com/questions/17483535/gridview-adapter-within-an-adapter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!