package com.marshalchen.common.demoofui.dynamicgrid.example; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.TaskStackBuilder; import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBarActivity; import android.view.View; import android.widget.AdapterView; import android.widget.Toast; import com.marshalchen.common.uimodule.dynamicgrid.DynamicGridView; import com.marshalchen.common.demoofui.R; import java.util.ArrayList; import java.util.Arrays; public class DynamicGridActivity extends ActionBarActivity { private DynamicGridView gridView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.dynamic_grid_view_activity_grid); ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); gridView = (DynamicGridView) findViewById(R.id.dynamic_grid_view); gridView.setAdapter(new CheeseDynamicAdapter(this, new ArrayList<String>(Arrays.asList(Cheeses.sCheeseStrings)), 3)); gridView.setVerticalScrollBarEnabled(false); // gridView.setEnabled(false); // add callback to stop edit mode if needed gridView.setOnDropListener(new DynamicGridView.OnDropListener() { @Override public void onActionDrop() { gridView.stopEditMode(); } }); // gridView.setOnTouchListener(new View.OnTouchListener() { // @Override // public boolean onTouch(View v, MotionEvent event) { // if (gridView.isEditMode()) { // gridView.stopEditMode(); // } // return false; // } // }); gridView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { gridView.startEditMode(); return false; } }); gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Toast.makeText(DynamicGridActivity.this, parent.getAdapter().getItem(position).toString() + " " + gridView.isEditMode(), Toast.LENGTH_SHORT).show(); } }); } @Override public void onBackPressed() { if (gridView.isEditMode()) { gridView.stopEditMode(); } else { super.onBackPressed(); } } @Override public Intent getSupportParentActivityIntent() { this.finish(); return super.getSupportParentActivityIntent(); } @Override public void onCreateSupportNavigateUpTaskStack(TaskStackBuilder builder) { super.onCreateSupportNavigateUpTaskStack(builder); } }