第一个app项目

又是新的一年开学季,这学期开始学习Android应用软件。

我的第一个Android应用程序是一个非常非常简便的加法计算,创建项目的过程就不多说了。

创建的项目会生成许多的文件(如下图),但是我现在只运用了3个文件,一个是res下的layout下的页面布局activity_main.xml文件和values下的string.xml,和src根目录下的后台Java文件MainActivity.java。

在string.xml下是页面中需要用到的一些文本和字符,默认的信息是Hello world!,我们可以在string.xml中添加自己需要的文本和字符信息(如下左图),当自己添加的信息被保存的时候,这些信息就会自动向gen目录下的R.java文件注册自己添加的信息(如下右图)。

                          

在activity_main.xml中我们可以自己设置页面的布局方式,并调用string.xml中的文本和字符信息,我自己设置的简单页面如图所示

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    
    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">


    <EditText 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="text"
        android:id="@+id/first"
        />
    
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/jiahao" />
    
    <EditText 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="text"
        android:id="@+id/second"/>
    
    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/denghao"/>
    
    <EditText 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="text"
        android:id="@+id/third"/>
    
    </LinearLayout>
    
    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/jisuan"
        android:id="@+id/js"/>
    
</LinearLayout>


这样我们就可以对这个页面进行事务的处理,在Java文件中编写后台程序,我们要对变量进行注册(如下图),如果不对变量进行注册你的程序可能什么问题,但是当发布到APP虚拟机时可能就会提示一段英文信息,开始我也是没对按钮进行注册,发布到虚拟机时总是出现英文信息,后来才在同学的帮助下发现按钮没有进行注册敲打

下面就是具体的单击事务的处理代码(如下图)。


最后这个简单的加法计算过程发布到虚拟机上的运行结果(如图所示)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值