单击android中主视图的处理程序

时间:2012-03-03 11:24:17

标签: android handler

我们可以为主视图设置onclick监听器,我的意思是setcontentview(main),我可以为此设置一个点击处理程序。我试过但听众没有回应主要观点。

1 个答案:

答案 0 :(得分: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>