publicclassMainAbilitySliceextendsAbilitySliceimplementsComponent.ClickedListener{Button but;@OverridepublicvoidonStart(Intent intent){super.onStart(intent);super.setUIContent(ResourceTable.Layout_ability_main);//1. 找到按钮 id
but =(Button)findComponentById(ResourceTable.Id_but1);//2.给按钮添加点击事件//如果没有添加点击事件,那么用鼠标点击按钮是没有任何反应//如果添加了点击事件,鼠标点击之后就可以执行对应的代码了//
but.setClickedListener(this);}@OverridepublicvoidonActive(){super.onActive();}@OverridepublicvoidonForeground(Intent intent){super.onForeground(intent);}@OverridepublicvoidonClick(Component component){//点击按钮只要执行的代码//跳转到第二个页面if(component == but ){//只有点击个按钮,才能跳转//跳转到哪个页面中(意图)Intent i =newIntent();//包含了页面跳转的信息Operation operation =newIntent.OperationBuilder()//要跳转到哪个设备上,如果传递一个空的内容,表示跳转到本机.withDeviceId("")//要跳转到哪个应用上,小括号里面可以写包名.withBundleName("com.example.myapplication")//要跳转的页面.withAbilityName("com.example.myapplication.SecondAbility")//表示将上面的三个信息进行打包.build();//把打包之后的operation设置到意图当中
i.setOperation(operation);//跳转页面startAbility(i);}}}