最近发几条质疑华鸿蒙系统的微头条,受了很多网友的嘲笑,我准备零基础自学App开发,我自己是运维,主要工作是维护Linux和Windows 服务器,同时兼桌面运维和网络。
废话不说,这是今天下午的成果。
安装开发工具创建项目自动下载gradle
耗时3个小时完工
代码如下: ability_main.xml
MainAbility.java
package com.example.demo;import com.example.demo.slice.MainAbilitySlice;import ohos.aafwk.ability.Ability;import ohos.aafwk.content.intent;import ohos.agp.components.Button;import ohos.agp.components.Component;import ohos.agp.components.Text;import ohos.agp.components.TextField;public class MainAbility extends Ability { @Override public void onStart(Intent intent) { super.onStart(intent); super.setUIContent(ResourceTable.Layout_ability_main); super.setMainRoute(MainAbilitySlice.class.getName()); Button button_add = (Button) findComponentById(ResourceTable.Id_add); button_add.setClickedListener(new Component.ClickedListener(){ @Override public void onClick(Component component) { TextField text_x = (TextField) findComponentById(ResourceTable.Id_x); int x = Integer.parseInt(text_x.getText()); TextField text_y = (TextField) findComponentById(ResourceTable.Id_y); int y = Integer.parseInt(text_y.getText()); int result = x y; TextField text_result = (TextField) findComponentById(ResourceTable.Id_result); text_result.setText(String.valueOf(result)); System.out.println(result); } }); } @Override public void onActive() { super.onActive(); } @Override public void onForeground(Intent intent) { super.onForeground(intent); }}
明天做好签名准备打包hap
花粉社群VIP加油站
猜你喜欢