@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.col1: mGridView.setColumnCount(1); break; case R.id.col2: mGridView.setColumnCount(2); break; case R.id.col3: mGridView.setColumnCount(3); break; } return true; }
@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); }