2014-03-27 25 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; 
     } 
    }); 
相關問題