本文介绍了MergeAdapter与GridView的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

库:





  • https://github.com/commonsguy/cwac-merge
  • https://github.com/maurycyw/StaggeredGridView
  • https://github.com/chrisbanes/Android-PullToRefresh

我想补充一个gridview适配器MergeAdapter。

I'd like to add a gridview adapter with MergeAdapter.

1的方式,如果你设置适配器:

plv = (PullToRefreshListView) LayoutInflater.from(context).inflate(
                    R.layout.layout_listview_in_viewpager, container, false);
adapter = new MergeAdapter();
sadapter = new StaggeredAdapter(BaseSampleActivity.this, R.id.imageView1, urls);
adapter.addAdapter(sadapter);
plv.setAdapter(adapter);

然后,它像一个列表视图。

Then it works like a list view.

第二种方法,如果你建立一个观点:

plv = (PullToRefreshListView) LayoutInflater.from(context).inflate(
                    R.layout.layout_listview_in_viewpager, container, false);
adapter = new MergeAdapter();
adapter.addView(buildlabel3(context));
plv.setAdapter(adapter);

public View buildlabel3(Context context) {
        // TODO Auto-generated method stub

        RelativeLayout v = (RelativeLayout)LayoutInflater.from(context).inflate(R.layout.activity_main, null);
        StaggeredGridView gridView = (StaggeredGridView) v.findViewById(R.id.staggeredGridView1);

        int margin = getResources().getDimensionPixelSize(R.dimen.margin);

        gridView.setItemMargin(margin); // set the GridView margin
        gridView.setPadding(margin, 0, margin, 0); // have the margin on the sides as well

        StaggeredAdapter sadapter = new StaggeredAdapter(BaseSampleActivity.this, R.id.imageView1, urls);

        gridView.setAdapter(sadapter);
        sadapter.notifyDataSetChanged();
        Log.e("view", v.toString());
        return v;
    }

然后,它并没有显示任何东西,没有错误。

Then it doesn't show anything and with no error.

推荐答案

addView() MergeAdapter 设计为的ListView 标题等。你,而是试图把 GridView控件作为内部元素的一些其它适配器视图正在使用 MergeAdapter 。这不是由 MergeAdapter 支持,并把一个 GridView控件的另一个内部适配器视图不可能不管你如何努力去做工作。

addView() on MergeAdapter is designed for ListView headers and the like. You, instead, are attempting to put a GridView as an element inside of some other AdapterView that is using the MergeAdapter. That is not supported by MergeAdapter, and putting a GridView inside of another AdapterView is unlikely to work no matter how you try to do it.

另外,我不建议作出适配器静态确实的不是 MergeAdapter ,因为它会重新present一个显著内存泄漏(和不必要摆在首位)。

Also, I do not recommend making an Adapter be static, and certainly not a MergeAdapter, as it would represent a significant memory leak (and is unnecessary in the first place).

这篇关于MergeAdapter与GridView的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-11 22:30