开发者

drag/slide finger to perform onclick buttons- multitouch

i have a game, consisting of 7 buttons , arranged such that 1 button is in the center and rest 6 around it. click on the buttons results in change in textview. using click can really be cumbersome for the user, therefore i would like to add functionality of dragging finger over buttons to perform onclick ..something similar to boggle type of games like -> https://market.android.com/details?id=com.ant.wordfind.client&feature=search_result

i have tried to implement the same ,problem is when i drag of finger 开发者_JAVA技巧only one button gets registered , even if i press other buttons by dragging cursor -> other button touch are just ignored.given the following code.

public boolean onTouch(View v, MotionEvent arg1) 
{ 
                if(arg1.getAction() ==MotionEvent.ACTION_MOVE) 
        { 
                Button b; 
                switch (v.getId()) 
        { 
        case R.id.b1: 
        case R.id.b2: 
        case R.id.b3: 
        case R.id.b4: 
        case R.id.b5: 
        case R.id.b6: 
        case R.id.b7: 
              b = (Button)findViewById(v.getId()); 
              b.performClick(); 
                break; 
        } 
     return true; 
        }

am i missing somethng ? wht i want is whn buttons are touched ..they perform onclick functionality.once one button click is registered rest touches are ignored

any help would be appreciated .

i dont want something like piano/soundboard where there is continuous click of button ..but just one click as i drag finger over the button thanks !


At onTouch(), you shouldn't always use return true. Return false if you want the subsequent actions to be captured.

onTouch() - This returns a boolean to indicate whether your listener consumes this event. The important thing is that this event can have multiple actions that follow each other. So, if you return false when the down action event is received, you indicate that you have not consumed the event and are also not interested in subsequent actions from this event. Thus, you will not be called for any other actions within the event, such as a finger gesture, or the eventual up action event.

Ref: http://developer.android.com/guide/topics/ui/ui-events.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜