从其适配器 - Android访问gridview

时间:2013-05-10 04:53:03

标签: android gridview android-gridview smooth-scrolling

我有一个带有我自己的适配器的自定义gridview。我正在处理gridview按钮点击适配器的实现。按下按钮后我想显示一个快速操作栏,如“确认”然后如果用户按下确认操作,然后gridview自动平滑滚动到另一个位置。这就是我想要的。现在我已经成功创建了快速操作栏,但我不知道如何实现smoothscroll。

3 个答案:

答案 0 :(得分:3)

  

要在Adapter类中访问GridView,可以使用Arun的答案:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
     ....
     GridView gv = (GridView)parent;

}
  

要实现平滑滚动,请检查以下答案:   Smooth Scrolling implementation

答案 1 :(得分:2)

getView中使用

GridView gv=(GridView)parent;

获取gridView

修改

延迟顺利滚动

gridView.postDelayed(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                gridView.smoothScrollBy(1000, 10000);
            }
        }, 1000);

答案 2 :(得分:0)

parentIn my case GridItemClickListner didn't worked for some reason. I access the Gridview from Adapter class using this

public View getView(final int position, View convertView, ViewGroup parent) {
        convertView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
          ((GridView) v.getParent()).performItemClick(v, position, v.getId());
                         (OR)
          ((GridView)parent).performItemClick(v, position, v.getId());
   }
 });
}