我正在制作一个需要在网格视图中交换图像的应用程序。这是代码......我怎么能实现交换:
活动
public class GameActivity extends Activity
implements OnTouchListener
{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Intent intent = getIntent();
setContentView(R.layout.layout_game);
//create grid view
splitImage();
GridView gridView = new GridView(this);
gridView = (GridView)findViewById(R.id.grid_view);
final ImageAdapter images = new ImageAdapter(this,chunkedImages);
final GridView gV = gridView;
gridView.setAdapter(images);
gridView.setOnTouchListener(this);
}
public boolean onTouch(View v, MotionEvent me) {
switch(me.getAction())
{
case MotionEvent.ACTION_DOWN :
Toast.makeText(GameActivity.this, "down ", Toast.LENGTH_SHORT).show();
break;
case MotionEvent.ACTION_UP :
Toast.makeText(GameActivity.this, "up " , Toast.LENGTH_SHORT).show();
break;
case MotionEvent.ACTION_MOVE :
//Toast.makeText(GameActivity.this, "move", Toast.LENGTH_SHORT).show();
break;
}
return true;
}
}
触摸图像时,它会吐司掉下来,然后移开手指就会放弃。但是如何交换图像我无法理解。