动态GridView作为数组

时间:2014-12-03 10:18:55

标签: android gridview

嘿伙计们我试图创建一个具有线性布局的应用程序。线性布局可能有多个网格视图,它将动态生成。我正在尝试这样做,但它只添加一个网格视图不超过一。有人对此有答案吗?

private GridView gv[];
    .
    .
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ...
    ....
    gv = new GridView[2];
    ....
    .....
    protected void onPostExecute(Boolean result) {
            if (al1.length == 2)
                linearLayout.setWeightSum(2.0f);
            for (int i = 0; i < al1.length; i++) {
                gv[i] = new GridView(getApplicationContext());
                if (al1.length == 2) {
                    gv[i].setNumColumns(1);
                } else
                {
                    gv[i].setNumColumns(2);
                }
                gv[i].setAdapter(new gridadapter(getApplicationContext(),
                        al1[i]));
                linearLayout.addView(gv[i]);

1 个答案:

答案 0 :(得分:2)

以列表视图为例,采用水平纹理作为项目的线性布局...然后将您的项目添加到此线性布局......它将按照您的要求工作,并使工作更轻松,更快......

告诉我你是否想要更多解释......