尝试学习android / java,所以我正在为我女儿做一个简单的游戏。但我无法弄清楚我的参数中需要什么表达式?
我找到了一个可以通过' onCreate'传递的答案,但我想单独传递它,因为我觉得这是学习参数的好习惯。
爪哇
public class DragDropActivity extends MainActivity {
private ImageView dragPeppa = (ImageView) findViewById(R.id.drag_peppa);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.drag_drop_layout);
addTouchListener();
onDrag(DragDropActivity.this, /** [DON'T KNOW WHAT TO PUT HERE] **/ );
}
public void addTouchListener() {
dragPeppa.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
view.startDrag(null, shadowBuilder, view, 0);
view.setVisibility(View.INVISIBLE);
return true;
} else {
return false;
}
}
});
}
public boolean onDrag(View layoutview, DragEvent dragevent) {
int action = dragevent.getAction();
switch (action) {
case DragEvent.ACTION_DRAG_STARTED:
Log.d("DragDropActivity", "Drag event started");
break;
case DragEvent.ACTION_DRAG_ENTERED:
Log.d("DragDropActivity", "Drag event entered into " + layoutview.toString());
break;
case DragEvent.ACTION_DRAG_EXITED:
Log.d("DragDropActivity", "Drag event exited from " + layoutview.toString());
break;
case DragEvent.ACTION_DROP:
Log.d("DragDropActivity", "Dropped");
View view = (View) dragevent.getLocalState();
ViewGroup owner = (ViewGroup) view.getParent();
owner.removeView(view);
LinearLayout container = (LinearLayout) layoutview;
container.addView(view);
view.setVisibility(View.VISIBLE);
break;
case DragEvent.ACTION_DRAG_ENDED:
Log.d("DragDropActivity", "Drag ended");
break;
default:
break;
}
return true;
}
}