我这里有一个自定义视图,然后我想要一些小部件来配合它。
<com.zone.manager.Tab3
    android:id="@+id/tab3_display"
    android:layout_width="fill_parent"
    android:layout_height="620dp" >
<Button
    android:id="@+id/addZone"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Add Zone" />
</com.zone.manager.Tab3>
现在我想将该按钮设置为 onclicklistener 以便我可以在 View 类中使用它做一些事情,所以我这样做了......
addZone = (Button) findViewById(R.id.addZone);
  addZone.setOnClickListener(this);
我把它设置在
public class Tab3 extends ViewGroup implements OnTouchListener, OnClickListener
    Public Tab3(Context context, AttributeSet attrs) 
    {
    super (context, attrs); 
    // here
    }
当我扩展 ViewGroup 时,它让我实现了这个
@Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) 
    {
        // TODO Auto-generated method stub
    }
为了完成这项工作,我是否应该在这里放一些东西?
但是当我尝试运行应用程序时它崩溃了,但是如果我 //addZone.setOnClickListener(this);应用程序运行良好,对我有什么帮助吗?
标签
        th.setup();
        TabSpec specs = th.newTabSpec("tag0");
        specs.setContent(R.id.connecttionTab);
        specs.setIndicator("Connection Tab");
        th.addTab(specs);
        specs = th.newTabSpec("tag1");
        specs.setContent(R.id.tab1);
        specs.setIndicator("Zone Manager");
        th.addTab(specs);
        specs = th.newTabSpec("tag2");
        specs.setContent(R.id.tab2);
        specs.setIndicator("",res.getDrawable(R.drawable.ic_tab_vaccontrol));
        th.addTab(specs);
        //this is the tab that has all this vvv
        specs = th.newTabSpec("tag3");
        specs.setContent(R.id.tab3);
        specs.setIndicator("Graphical Layout");
        th.addTab(specs);