2013-03-01 58 views
3

我試圖檢測長按並獲得Android的,不能讓基法setOnLongClickListener工作

The methed 'setOnLongClickListener' in type view is not applicable for the argument 'new OnLongClickListener()'

的代碼看起來像

t.setOnLongClickListener(new OnLongClickListener() { 
    @Override 
    public boolean onLongClick(View v) { 
     //Offer additional options when the view is held. 
      MakeRingtune(strLastSound); 
     return true; 
    } 
}); 
+0

什麼樣的變量爲t? – hardartcore 2013-03-01 12:59:50

+0

您試圖在LongClickListener上應用哪個視圖? – GrIsHu 2013-03-01 13:00:44

回答

3

有多種內部類名爲OnLongClickListener在android API中:View.OnLongClickListenerAdapterView.OnLongClickListener

因此請檢查您的導入聲明並確保您使用正確的導入聲明。

3

嘗試下面:

t1.setOnLongClickListener(new View.OnLongClickListener() { <--- check here. 
    @Override 
    public boolean onLongClick(View v) { 
     // TODO Auto-generated method stub 
     Toast.makeText(getBaseContext(), "Long Clicked", Toast.LENGTH_SHORT).show(); 
     return true; 
    } 
}); 
+0

真棒..關鍵是「查看」一詞。 – baash05 2015-01-12 06:36:03