2014-03-27 27 views
0

我们正在制作离线字典。所以为此,我们使用long click()方法。在使用长按()选择文本文件中的单词后,我们需要一个按钮来显示意思。因此,我们该如何做到这一点?我们需要一个从我们的字典中引用的按钮。 我们长按的代码是 -我如何使用Longclick方法android

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.activity_main); 

    gestureDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() { 

     public void onLongPress(MotionEvent e) { 
      Toast.makeText(getApplicationContext(), 
            "kutu", 
            Toast.LENGTH_SHORT).show(); 

      Log.e("", "Longpress detected"); 
     } 

    }); 
} 

public boolean onTouchEvent(MotionEvent event) { 
    return gestureDetector.onTouchEvent(event); 
} 

回答

0

Use onlongclick listener for this

final Button button = (Button) findViewById(R.id.button_id); 
    button.setOnLongClickListener(new View.OnLongClickListener() { 
     public boolean onLongClick(View v) { 
      // Perform action on click 
      return true; 
     } 
    }); 
相关问题