在主要活动代码,做这样的事情
public class TestActivity extends Activity implements
OnTouchListener, OnLongClickListener, OnKeyListener,
OnClickListener, OnFocusChangeListener{
CustomUI = (CustomView) findViewById(R.id.custom_ui);
CustomUI.addListener(this);
CustomUI.setOnClickListener(this);
CustomUI.setOnFocusChangeListener(this);
CustomUI.setOnLongClickListener(this);
CustomUI.setOnTouchListener(this);
CustomUI.setOnKeyListener(this);
}
而且你不能把属性在亲戚的布局,你必须包括您的自定义用户界面是此布局.. 。like like
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<com.company.some.CustomView
android:id="@+id/custom_ui"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
/>
</RelativeLayout>