开发者

How to stop drawing GridView items BEFORE the parent View becomes scrollable?

I'm trying to populate a ViewFlipper with a GridView, but with a paging capability rather than scrolling. The GridView will fill out a single "page" (one complete page without scrolling), and start filling out the next View in the ViewFlipper with the next bit of the data set.

I need to dynamically fill the pages, as the screen sizes will vary. This GridView sports a custom adapter class with a getView() override, so I was thinking the most elegant solution would be to draw the view as normal in the GridView, but this is where I run into some confusion:

Two things:

How can i tell the getView() function to write the GridView items to the next View in the ViewFlipper? And by that token, how can I know when the screen fills to just before the scroll bar 开发者_开发问答pops up (I don't want scrollable lists, which was the whole point in using a ViewFlipper).

Or is there a better solution that i just haven't found yet? I couldn't find an example in the API demos and little info here on stackoverflow except this, which got me started, but I still need the above two suggestions to make this solution work (unless there's something better): Android ViewFlipper not flipping

The GridView adapter:

// custom adapter made for the GridView
public class ButtonAdapter extends BaseAdapter {
    private Context mContext;
    private List<Map<String, String>> mData;
    private int mLayout;

    public ButtonAdapter(Context c, int layout, List<Map<String, String>> list) {
        this.mContext = c;
        this.mData = list;
        this.mLayout=layout;
    }

    public int getCount() {
        return mData.size();
    }

    public Object getItem(int position) {
        return mData.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        Button btn = null;

        if(convertView==null) {
            convertView = inflater.inflate(this.mLayout, null);
        }

        btn = (Button)convertView.findViewById(R.id.grid_btn);
        if(btn != null) {
            //btn.setPadding(8,8,8,8);
            btn.setText(mData.get(position).get("label"));
            btn.setId(position);
        }

        return convertView;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜