2016-07-26 1 views
1
Hbutton.setOnClickListener(
    new Button.OnLongClickListener(){ 
     public boolean onLongClick(View v){ 
      TextView Htext = (TextView) findViewById(R.id.Htext); 
      Htext.setText("Hunny"); 
      return true; 
     } 
    } 
); 

このコードでは何が間違っていますか?それはあなたがonLongClickListener設定する必要がERROR匿名android.view.View.OnLongClickListener

(anonymous android.view.View.OnLongClickListener) 
+0

Hbuttonあなたはfindviewbyidようなあなたのファイルにinitを持っていますか? – PriyankaChauhan

答えて

2

与え :

Hbutton.setOnLongClickListener(
     new Button.OnLongClickListener(){ 
      public boolean onLongClick(View v){ 
       TextView Htext = (TextView) findViewById(R.id.Htext); 
       Htext.setText("Hunny"); 
       return true; 
      } 
     } 

); 
0

をこの方法を試してみてくださいを、

Button Hbutton = (Button) findViewById(R.id.YOUR_BUTTON_ID); 

Hbutton.setOnLongClickListener(new View.OnLongClickListener() { 

     @Override 
     public boolean onLongClick(View v) { 
      // TODO Auto-generated method stub 

      //do your stuff here 

      return true; 
     } 
    });