2012-03-03 46 views

回答

1

是的,你可以創建它像...

RelativeLayout rMain = (RelativeLayout)findviewById(R.id.mainlayout); 
rMain.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       //here you can do your code on click main....    
      } 
     }); 

main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/mainlayout" 
    android:orientation="vertical" > 

<!-Any view is here-> 
    <Button/> 

</RelativeLayout> 
+0

我認爲這個問題是@Override 其刪除這一點,這就是爲什麼我不能有點擊處理程序。 – Programmer 2012-03-03 11:34:53

+0

nop @ovverride永遠不會產生任何問題... – 2012-03-03 11:36:25

+0

當您創建錯誤的方法時,@Override所做的所有事情都會給您一個編譯時錯誤,而不是讓您處理由錯誤引發的各種運行時錯誤和錯誤。 – 2012-03-03 13:15:39