private void onLoadMoreItems() { final ArrayList<String> sampleData = WaterfallData.generateSampleData(); for (String data : sampleData) { mAdapter.add(data); } // stash all the data in our backing store mData.addAll(sampleData); // notify the adapter that we can update now mAdapter.notifyDataSetChanged(); mHasRequestedMore = false; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_user); setTitle("SGV"); mGridView = (StaggeredGridView) findViewById(R.id.grid_view); LayoutInflater layoutInflater = getLayoutInflater(); View header = layoutInflater.inflate(R.layout.waterfall_header_item, null); View footer = layoutInflater.inflate(R.layout.waterfall_header_item, null); TextView txtHeaderTitle = (TextView) header.findViewById(R.id.txt_title); TextView txtFooterTitle = (TextView) footer.findViewById(R.id.txt_title); txtHeaderTitle.setText("我的游记"); txtFooterTitle.setText("THE FOOTER!"); mGridView.addHeaderView(header); mGridView.addFooterView(footer); mAdapter = new WaterfallAdapter(this, R.id.txt_line1); // do we have saved data? if (savedInstanceState != null) { mData = savedInstanceState.getStringArrayList(SAVED_DATA_KEY); } if (mData == null) { mData = WaterfallData.generateSampleData(); } for (String data : mData) { mAdapter.add(data); } mGridView.setAdapter(mAdapter); mGridView.setOnScrollListener(this); mGridView.setOnItemClickListener(this); mGridView.setOnItemLongClickListener(this); }