2012-09-12 54 views
0

我在定義在子對象上的按鈕控件中遇到onclicklistener問題。這個事件似乎永遠不會被解僱。 ontouchlistener似乎在工作。有沒有人遇到過Android 4.0的這個問題?Android 4.0上的onclicklistener

+1

把你的代碼.. –

回答

0

嘗試

// Create an anonymous implementation of OnClickListener 
private OnClickListener mCorkyListener = new OnClickListener() { 
    public void onClick(View v) { 
     // do something when the button is clicked 
    } 
}; 

protected void onCreate(Bundle savedValues) { 
    ... 
    // Capture our button from layout 
    Button button = (Button)findViewById(R.id.corky); 
    // Register the onClick listener with the implementation above 
    button.setOnClickListener(mCorkyListener); 
    ... 
} 

XML:

<Button android:layout_height="wrap_content" 
    android:id="@+id/butHello" 
    android:layout_width="wrap_content" 
    android:text="Поздороваться" 
    android:onClick="butHello_Click"></Button> 

代碼:

public void butHello_Click(View v){ 
    edtext.setText("Здравствуй, друг"); 
} 

//複製從http://habrahabr.ru/post/114580/

0

點擊可以使用像

Button btnclick = (Button) findViewById(R.id.button1); 
    btnclick.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 

       // do here as require 

      } 
     }); 

}