Back to project page DynamicGrid.
The source code is released under:
Apache License
If you think the Android project DynamicGrid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.askerov.dynamicgrid.example; /*from ww w . j a v a 2 s . c o m*/ import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.AdapterView; import android.widget.Toast; import org.askerov.dynamicgrid.DynamicGridView; import java.util.ArrayList; import java.util.Arrays; public class GridActivity extends Activity { private static final String TAG = GridActivity.class.getName(); private DynamicGridView gridView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_grid); gridView = (DynamicGridView) findViewById(R.id.dynamic_grid); gridView.setAdapter(new CheeseDynamicAdapter(this, new ArrayList<String>(Arrays.asList(Cheeses.sCheeseStrings)), getResources().getInteger(R.integer.column_count))); // add callback to stop edit mode if needed // gridView.setOnDropListener(new DynamicGridView.OnDropListener() // { // @Override // public void onActionDrop() // { // gridView.stopEditMode(); // } // }); gridView.setOnDragListener(new DynamicGridView.OnDragListener() { @Override public void onDragStarted(int position) { Log.d(TAG, "drag started at position " + position); } @Override public void onDragPositionsChanged(int oldPosition, int newPosition) { Log.d(TAG, String.format("drag item position changed from %d to %d", oldPosition, newPosition)); } }); gridView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { gridView.startEditMode(position); return true; } }); gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Toast.makeText(GridActivity.this, parent.getAdapter().getItem(position).toString(), Toast.LENGTH_SHORT).show(); } }); } @Override public void onBackPressed() { if (gridView.isEditMode()) { gridView.stopEditMode(); } else { super.onBackPressed(); } } }