简体   繁体   中英

android button sender double click

i am new to android programming, i am trying to allow the blind user to add contact number, when he clicks one click he will listen to the key sound and in double clicks the pressed key is appended, when he clicks one click in key and then double click on another key it will append the previous number key not last key. my problem it will append last key not previous one.

here is my code :

 public void num_phone(View Sender)
    {
        btn = (Button)Sender;
        long currentTime =System.currentTimeMillis();
        if (currentTime - lastClickTime > DOUBLE_CLICK_TIME_DELTA) 
        {
            b=2;

            f=btn.getText().toString();
            Toast.makeText(MainActivity4.this, ""+f , Toast.LENGTH_SHORT).show();
        }

        else {
        if(isempty)
        {

            name.setText(f);
            isempty=false;

        }
        else if(!btn.getText().toString().equals("Erase"))
        {
            name.append(f);

        }
        else if(btn.getText().toString().equals("Erase"))
        {
            name.setText("");
        }
        }
        //String phoneNum = phone.getText().toString();
        lastClickTime = currentTime;

         detector = new GestureDetector(this, this);
            detector.setOnDoubleTapListener(this);


        //String alphabatic = name.getText().toString();
    }

Maybe you could just attach this double tap listener to a container that is holding those buttons (some sort of layout)?

You would get single clicks on buttons normally (and storing the information about which button was clicked last) and when user double taps one of the buttons (the whole layout) you would just force the click of the button that you've stored previously (single-clicked).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM