....
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 。