....
case 5:
sizeperbutton = sizeOfLayout/5;
for( i = 0; i<25; i++) {
buttons[i] = new Button(this)
ll.addView(buttons[i]);
ViewGroup.LayoutParams mParams = buttons[i].getLayoutParams();
mParams.height = sizeperbutton;
mParams.width = sizeperbutton;
int j = (int)(Math.random()*26);
buttons[i].setText(letterEN[j]);
buttons[i].setTag(i);
buttons[i].setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
Object tag = view.getTag();
if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){
/* Set the background drawable only for the button I've clicked, and get its text and append it to a textView*/
}
if(motionEvent.getAction() == MotionEvent.ACTION_MOVE){
/* Set the background drawable all the buttons I dragged through my finger and append their letters to the same textView*/
}
if(motionEvent.getAction() == MotionEvent.ACTION_UP){
/*Release touching, check if the text which is stacked to the textView is contained by a list.*/
}
return false;
}
});
}
在我的游戏活动中,它会在水平和垂直方向创建一个有5个按钮的区域。 所有这些都得到一个随机的字母,并获得触摸监听器,我认为不足以同时点击更多的对象,它只适用于一个按钮。我很欣赏任何来源或代码。我做了很长时间的研究,但最后我不得不要求提供信息。这就是我想要达到的目标:https://www.youtube.com/watch?v=NRIvZioTdMc。